Comments (8)
Oh, now I see that your directory structure is a bit unusual for this library.
However, you can use a workaround like this:
import i18n
i18n.load_path.append("src/Languages")
i18n.set("file_format", "json")
i18n.set("filename_format", "{namespace}.{format}")
i18n.set("namespace_delimiter", ":")
i18n.set("skip_locale_root_data", True)
def translate(key, locale, **kwargs):
return i18n.t(f"{locale}:{key}", **kwargs)
print(translate("Administration:LANGUAGES_LIST", "en-US", LANGUAGES="..."))
Placeholders in the JSON needs to be converted too. Example: {{LANGUAGES}}
becomes %{LANGUAGES}
.
from i18nice.
I've added a setting to properly support directory structure like yours.
You can read about it here.
from i18nice.
Can you elaborate on your question? Files are ok and this library has only global state, no per-object translations or something like that, so I don't understand your point.
I just had to import i18n in other files to use it, I wasn't sure if it would work.. But everything work like a charm there now !
from i18nice.
Yes, it is possible, but you'll need a different syntax for placeholders.
from i18nice.
Yes, it is possible, but you'll need a different syntax for placeholders.
Could you make me a small example ?
from i18nice.
Oh, now I see that your directory structure is a bit unusual for this library. However, you can use a workaround like this:
import i18n i18n.load_path.append("src/Languages") i18n.set("file_format", "json") i18n.set("filename_format", "{namespace}.{format}") i18n.set("namespace_delimiter", ":") i18n.set("skip_locale_root_data", True) def translate(key, locale, **kwargs): return i18n.t(f"{locale}:{key}", **kwargs) print(translate("Administration:LANGUAGES_LIST", "en-US", LANGUAGES="..."))Placeholders in the JSON needs to be converted too. Example:
{{LANGUAGES}}
becomes%{LANGUAGES}
.
Thanks a lot ! I'll try that as soon as I can !
from i18nice.
I've added a setting to properly support directory structure like yours.
You can read about it here.
setting to properly support directory structure like yours.You can read about it here.
Not being a Python user I'm a bit lost, what would be your advice to use the i18n translations over files ?
Is there a way to make it global for example ?
Fixed issue printing the t arg I just messed up myself
from i18nice.
Can you elaborate on your question? Files are ok and this library has only global state, no per-object translations or something like that, so I don't understand your point.
from i18nice.
Related Issues (10)
- PyPI support HOT 11
- Add support for yes/no variables HOT 2
- Feedback about python-i18n v0.6.0 HOT 1
- Request for Adding Support for Localized Key References HOT 8
- Support None as fallback locale HOT 4
- Add `py.typed` marker to work with PEP 561 HOT 2
- regression: ValueError exception when %% is used in string HOT 1
- cool
- conda recipe for i18nice HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18nice.