https://github.com/mberatsanli/multilangpy
multilangPY
https://github.com/mberatsanli/multilangpy
multilanguage-support python
Last synced: about 1 year ago
JSON representation
multilangPY
- Host: GitHub
- URL: https://github.com/mberatsanli/multilangpy
- Owner: mberatsanli
- Created: 2019-09-30T12:06:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T19:00:43.000Z (over 6 years ago)
- Last Synced: 2025-03-05T22:48:47.085Z (over 1 year ago)
- Topics: multilanguage-support, python
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# multilangPY
### Import the library
```python
from multilang import multilang
```
## Using
#### > How to starting
```python
mlang = multilang()
```
#### > Set Languages Directory
```python
mlang.set("dir", "../demo/langs/")
```
#### > whatIs function
```python
mlang.whatIs(value, print4me=False)
```
| value | what is does | ouput |
|--|--|--|
| lang or language | Prints the selected language | return
| dir or directory | Prints the selected directory | return
#### > List the language in the defined direcory
```python
mlang.languages(print4me=False, helper=False)
```
| paramters | what is does | output |
|-------------|--------------|--------|
| print4me | Print for you language file(s) in directory | array |
| helper | writes in detail the file(s) in directory. You just using with print4me. | just try :) |
#### > How to create the language file (json)
For example, the folder with the language files: `../multilang/languages/` and we create a language folder in the directory. Create `LANGUAGE.json` for example `ru.json` and `az.json`
`"CALL_NAME": "TEXT or WORD"`
```json
// ru.json
{
"merhaba": "Привет",
"merhaba_kullanici": "Привет %s"
}
// az.json
{
"merhaba": "Salamlar",
"merhaba_kullanici": "Salam %s"
}
```
#### > How to get the text or word
```python
mlang.get(CALLED NAME)
```
## Dynamic Example
You can use different languages within a project.
```python
from multilang import multilang
mlang = multilang()
mlang.set("lang", "tr")
print(mlang.get("merhaba_kullanici") % "Melih")
mlang.set("lang", "az")
print(mlang.get("merhaba_kullanici") % "canim ben")
```
```shell
Output;
> Merhaba Melih
> Salam canim ben
```
## Example Using
```python
# main.py
import multilang
mlang = multilang.multilang()
mlang.set("dir", "app/langs/") # Set the new directory
mlang.set("lang", "az") # Set az lang
mlang.get("merhaba") # Output (return): Salamlar
print(mlang.get("merhaba_kullanici") % "Melih") # Output (print): Salam Melih
```