GithubHelp home page GithubHelp logo

Comments (8)

andy-noisyduck avatar andy-noisyduck commented on June 30, 2024 1

Our use case is loading Catalog objects via a stream and this covers our scenario.

For full context we make games. We parse a folder full of .mo files to know what languages we have translations for, and then display the known options in a language menu so that the user can easily switch language.

Right now we are manually extracting the language header and reading it. It works fine, but it feels like it should have been part of the GetText library.

Thanks for your great work.

from gettext.net.

perpetualKid avatar perpetualKid commented on June 30, 2024 1

this is now fixed/updated in code.
A new package version (> 0.9.8) will be out in the next couple days

from gettext.net.

perpetualKid avatar perpetualKid commented on June 30, 2024

this is all based on the original NGetText code and I never looked into it, but can clearly see that using CultureInfo.CurrentUICulture certainly is not really a good idea.
I'll need to dig bit deeper to see if there are any side effects when changing this, but clearly should be changed.

from gettext.net.

perpetualKid avatar perpetualKid commented on June 30, 2024

looking further, I could see two issues here:

  • typically the culture is set in the application, and the appropriate catalog loaded i.e.
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(fr-FR);
ICatalog catalog = new Catalog("myCatalog");

or alternatively

ICatalog catalog = new Catalog("myCatalog", new CultureInfo(fr-FR));

in that case, the catalog would try to load the catalog matching the given or current culture, so the CultureInfo of the catalog should match that. However, if a catalog for the exact culture ("fr-FR") is not found, it will lookup the hierarchy, and i.e. find a catalog matching "fr" only. In that case, the CultureInfo property of the catalog would still be "fr-FR" instead of "fr", which needs to be updated.

  • the other case is if you're pointing directly to a file (stream) or ILoader interface. In that case, your application CultureInfo.CurrentUICulture may be i.e. en-US, but you may open a catalog from stream
ICatalog catalog = new Catalog(new Catalog(new FileStream("catalog_fr-FR.mo"));

so the catalog's CultureInfo will be en-US instead of fr-FR which is wrong obviously.

I'll update both cases. Could you just confirm this is covering your scenario, or is there something else I haven't seen yet?

from gettext.net.

perpetualKid avatar perpetualKid commented on June 30, 2024

reasonable to expect the CultureInfo property set out of the loaded catalog, I'll work on that.

just for curiousity, how are the *.mo files named?
In most cases I've seen and used, either the mo-files where using the language code as filename (fr-FR.mo), or in a respective folder structure (fr-FR\catalog.mo)

from gettext.net.

andy-noisyduck avatar andy-noisyduck commented on June 30, 2024

just for curiousity, how are the *.mo files named?

In our case we also use the locale as the filename. Normally just the neutral locale (e.g. fr.mo) unless we have some region specific translations.

This does mean we could have fallen back to the filename to also know the catalog's locale, or to know available locales without actually parsing them, but when you have a bunch of files being generated by external tooling its quite easy to copy the wrong file or name it incorrectly. It's safer to validate against the language header.

from gettext.net.

perpetualKid avatar perpetualKid commented on June 30, 2024

https://www.nuget.org/packages/GetText.NET/0.9.9

from gettext.net.

andy-noisyduck avatar andy-noisyduck commented on June 30, 2024

Perfect. Thanks for the quick update.

from gettext.net.

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.