Giter VIP home page Giter VIP logo

Comments (3)

fabianjs avatar fabianjs commented on August 17, 2024 1

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.

clmnt-sg avatar clmnt-sg commented on August 17, 2024

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.

perrotuerto avatar perrotuerto commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.