turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

Consider to add a way of getting the entire tranalations for a language #244

Open jonnybee opened 8 years ago

jonnybee commented 8 years ago

We use Jed (https://slexaxton.github.io/Jed/) for gettext/i18n in javascript on the client side and need a way of transferring translations for the clients language as JSON data. Thee is also several other gettext javacript libraries out there.

What i have done is to created my own implementation of TextLocalizer and added method so can access the cached (or load into cache) translations for a given language.

Would it make sense to add this to the standard i18n TextLocalizer and expose this on the HttContext Extensions?

We could then either generate static json files on the server or serve them up dynamically based on the context extension.

I should also note that we have our own database repository for messages so we do not want to do any postprocessing or reading of the .po files.

If you agree then I can make the necessary changes and issue a PR.

turquoiseowl commented 8 years ago

Sounds interesting. Would you clarify what Jed gives you over using this library alone? Thanks.

jonnybee commented 8 years ago

When you build dynamic forms/html in javascript on the client and needs localizable labels, buttons, headin etc and we do not want to localize the javascripts themselves. The javascript may be cache and is identical for all languages.

In essence we call a javascript function to get the "translated" text and and I also extended the PostBuild to search for the javascript function. Another alternate would be to add a separate class that just specified the localizable messages in C# and use the standard parsing but it wasn't much work and our devs were happy to not have to keep this file in sync with the javascrips.

turquoiseowl commented 8 years ago

I see, you don't want to use i18n to localize the javascript. Any particular reason for that?

From what I can tell from Jed, the way you specify strings is more convoluted than the nugget notation. Is that fair to say? Would you provide a little snippet of some Jed-localized Javascript?

berniezhao commented 8 years ago

@jonnybee it is not ideal but currently I have server side read database and export to an HTML page with nuggets, then parse them into a PO file using c#. Then you can use po2json or whatever tool to convert them to static JSON file. The client side messages doesn't change often so this entire process is being trigger manually by a "re-index" admin page.