Create-Multi-Langs is a library for creating code file from translated csv file.
Project description
Create-Multi-Langs
Create-Multi-Langs is a package to create code for multi-lingual sites development,
Features
- Use CSV file grid table as translated source data instead of JSON to better manage translations.
- Output code language support python, go, javascript(ES6), typescript.
- No more map or dict like so, but use property to get
code intelligence. - Support watching mode for source csv file.
Install
pip install create-multi-langs
Prepare Data
prepare csv data by yourself, liek valid_format.csv:
| _field | zh-tw | en | _note |
|---|---|---|---|
| SelectLang | 繁體中文 | English | # select language |
| Login | 登入 | Login | used for login button |
| Hello | 您好,歡迎 | Hello,Welcome | pop up greeting message |
- Use CSV file as source data, a grid table is easier to manage for multi-lingual application.
_fieldand_noteare preserved column names, others column names are considered as language code- the values under column
_field, will become the field name in code file, but constraint the name with common naming rule of which language - the values under column
_note, will become the comment for code docs
Usage
create-multi-langs valid_format.csv generated.py
- support output language:
typscript,javascript,go,python - the generated code is determined by your output filename extension like: .py .go .js .ts .mjs
Testing
import from generated.py:
from generated import MultiLangs, ZH_TW, EN
ml = MultiLangs(ZH_TW)
assert ml.hello == "您好,歡迎"
assert ml.login == "登入"
assert ml.select_lang == "繁體中文"
ml.set_lang(EN)
assert ml.hello == "Hello,Welcome"
assert ml.login == "Login"
assert ml.select_lang == "English"
import from generated.js:
import { ml, setLang } from "./generated_frontend.mjs"
var compare = function(expect_value, actual_value) {
if (expect_value !== actual_value) {
return `[Error] expect '${expect_value}' but got '${actual_value}'\n`
}
return ""
}
var errs = ""
errs += compare(ml.hello, "您好,歡迎")
errs += compare(ml.login, "登入")
errs += compare(ml.selectLang, "繁體中文")
setLang("en")
errs += compare(ml.hello, "Hello,Welcome")
errs += compare(ml.login, "Login")
errs += compare(ml.selectLang, "English")
if (errs !== "") {
throw errs
}
import from generated.ts:
import { ml, setLang } from "./generated_frontend"
const compare = (expect_value: string, actual_value: string): string => {
if (expect_value !== actual_value) {
return `[Error] expect '${expect_value}' but got '${actual_value}'\n`
}
return ""
}
let errs = ""
errs += compare(ml.hello, "您好,歡迎")
errs += compare(ml.login, "登入")
errs += compare(ml.selectLang, "繁體中文")
setLang("en")
errs += compare(ml.hello, "Hello,Welcome")
errs += compare(ml.login, "Login")
errs += compare(ml.selectLang, "English")
if (errs !== "") {
throw errs
}
import from generated.go:
package generated
import "testing"
import "github.com/stretchr/testify/assert"
func TestGenerated(t *testing.T) {
ml := NewMultiLangs(ZHTW)
assert.Equal(t, "您好,歡迎", ml.Hello)
assert.Equal(t, "登入", ml.Login)
assert.Equal(t, "繁體中文", ml.SelectLang)
ml.SetLang(EN)
assert.Equal(t, "Hello,Welcome", ml.Hello)
assert.Equal(t, "Login", ml.Login)
assert.Equal(t, "English", ml.SelectLang)
}
Help
$ create-multi-langs --help
usage: create-multi-langs [-h] [--backend] [--py_typing] [--watch] [--sep SEP]
[--naming_rule NAMING_RULE]
from_csv to_file
Running DeepSpeech inference.
positional arguments:
from_csv Generate script from csv
to_file generate file path, support ext: .go .py .js .ts .mjs
optional arguments:
-h, --help show this help message and exit
--backend, -b Default is generate frontend script for js/ts
--py_typing, -t Default is generate python script without typing
--watch, -w Watch csv file changed
--sep SEP, -s SEP CSV seperated punctuation
--naming_rule NAMING_RULE, -n NAMING_RULE
specify your property style, [valid options]
`ucc`(UpperCamelCase), `lcc`(lowerCamelCase),
`upper`(ALL_UPERCASE_UNDERSCORE),
`lower`(all_lowercase_underscore) [default setting]
Go: `ucc`, Python: `lower`, Typescript: `lcc`,
javascript: `lcc`
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Create-Multi-Langs-0.1.1.tar.gz.
File metadata
- Download URL: Create-Multi-Langs-0.1.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cb964845eb7ae4e06378a831253e5d103870869a9c35c33724df5eec206743c
|
|
| MD5 |
709ba9a3b28aad17a1d3982d4299420a
|
|
| BLAKE2b-256 |
926b615fd3cea43a63a679aa9f9a5912242e9944000532edf51cddcc4c30ff4a
|
File details
Details for the file Create_Multi_Langs-0.1.1-py3-none-any.whl.
File metadata
- Download URL: Create_Multi_Langs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5606aad16c6cfab2c0f55f71de4d8b1c66d156281ded4bf96bd7d21e195a5838
|
|
| MD5 |
a3a88784bd833b2ff82d9be6006bcffb
|
|
| BLAKE2b-256 |
43b142486ba28c88a55eb9ee61c0e6cdf978221d2a5ce301c57ae8abea3710dc
|