Comments (3)
Hi,
Not the maintainer but was facing the same issue. Switching to json worked for me (see python-i18n/i18n/tests/resources/translations/en.json
for an example).
You will need to set
i18n.set('file_format', 'json')
i18n.set('filename_format', '{locale}.{format}')
and finally of course
i18n.load_path.append('path/to/translations/folder')
for this to work.
I would however be really interested in the correct YAML solution which I couldn't get to work either.
from python-i18n.
I actually achieved to make it work with YAML. By default, python-i18n uses YAML for external files. I just removed the i18n.set format thingy.
Also, I struggled a little bit with the path structure (and It's not that easy to find the issue because if the code does not find the right translation, It will print you the path that you're searching and not something like "Error translation not found" ^^)
Here is my code:
i18n.load_path.append('template')
i18n.set('locale', countrycode)
subject = i18n.t(f'{countrycode}.mail.subject', filename=filename)
body = i18n.t(f'{countrycode}.mail.body', filename=filename, error=i18n.t(f'{countrycode}.error.{errorcode}'))
And my paths structured like this:
template/en/mail.en.yml
from python-i18n.
In my case was that I didn't install pyyaml
. With it, works as @clmnt-sg said. Without it, works as @fabianjs suggested.
from python-i18n.
Related Issues (20)
- Pluralized strings seem broken HOT 1
- [BUG] Requirement package pyyaml won't be installed. HOT 3
- installation issue by poetry HOT 2
- Translation cannot start with % HOT 2
- YAML arrays not supported
- Tags HOT 2
- placeholder_delimiter config is ignored HOT 8
- Support loading translation files with importlib.resources files() API
- Support UTF encode
- Unable to load the translations HOT 2
- Subfolders don't work HOT 5
- module 'i18n' has no attribute 'load_path' HOT 1
- Translation tests failing
- Make pyyaml a requirement HOT 2
- I'm stuck on I18nFileLoadError: no loader available for extension yml HOT 4
- Maintained fork of python-i18n HOT 1
- How to exclude files from search path? HOT 1
- How to get reverse translation? HOT 1
- I18nFileLoadError for locales ‘am’ and ‘ml’ due to Misidentification in load_directory HOT 1
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 python-i18n.