Giter VIP home page Giter VIP logo

Comments (8)

solaluset avatar solaluset commented on August 17, 2024 1

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.

solaluset avatar solaluset commented on August 17, 2024 1

I've added a setting to properly support directory structure like yours.

You can read about it here.

from i18nice.

TheHellTower avatar TheHellTower commented on August 17, 2024 1

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.

solaluset avatar solaluset commented on August 17, 2024

Yes, it is possible, but you'll need a different syntax for placeholders.

from i18nice.

TheHellTower avatar TheHellTower commented on August 17, 2024

Yes, it is possible, but you'll need a different syntax for placeholders.

Could you make me a small example ?

from i18nice.

TheHellTower avatar TheHellTower commented on August 17, 2024

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.

TheHellTower avatar TheHellTower commented on August 17, 2024

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.

solaluset avatar solaluset commented on August 17, 2024

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)

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.