The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features

See the new Forums

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

22. November 2011, 21:00:30

stefanvd

Posts: 69

translation extension

Hi,

I got a Chrome extension and that use json files as translations. Here i see it is not possible to use direct json as translation. But i recent see that lastpass extension use json translation.
Can anybody know how to load a json message and give it just to a id element in a option.html page (json to javascript).

Or is a other solution to convert my Chrome extension translation json file to make it readable for my Opera extension. (with no change in the json files)

Kind Regards,
Stefan

25. November 2011, 18:26:00

Moderator

patrickhlauke

Posts: 29

The most appropriate way to create localised versions of extensions is outlined in this article http://dev.opera.com/articles/view/creating-multilingual-extensions/

Regarding separate json files for translation, I'm afraid I'm not familiar with Chrome's way of doing localisation. It sounds like it should be possible to read it via JS and process it accordingly, but this may need very specific scripting for each case (which is why we have a more generalised localisation model with the Widget packaging method)

25. November 2011, 20:52:35

stefanvd

Posts: 69

I use that already in my config file (for the titel & description).

But i got translations from my www.getlocalization.com project, (where i can download all translation in to a zip file) and there i use json for translation (Chrome need that). Now, i want that Opera also use that translation file, so that my HTML option page in my Opera extension can read this.

And the reference you said, i can't create here +/-25 different option.html page for all my translate languages.
Because if i change or add a option, i must change 25 html page. (and that is much work)
So need a solution to only replace the translation file by file (just like Chrome).
I see that it support "locales is a reserved folder name" that is good for json.
Or do you got a other idea javascript translation, or converteren the json to a other file type that i can use in Opera.... (this will be great smile


I see that Lastpass extension use json style for translation, it will be great to know how they to that. (also other extension developer would like it the option).

27. November 2011, 11:17:11

d4n3

Posts: 957

You could put the localized translation.json files inside locales and then load the current translation.json from javascript (you just reference it as a normal file relative to extension root folder). Look at the description of the language-matching algorithm in the article above to see how this works.

I'm sure there's multiple libraries for localization from JSON in javascript, or you could write something yourself.

27. November 2011, 11:26:28

stefanvd

Posts: 69

Thanks for you reply.
But still the problem is how to get it from javascript, can't figure it out to receive that (from json to javascript) in code.
If you know a example, then it will be great. smile

27. November 2011, 18:01:15

d4n3

Posts: 957

Oh, just use a XMLHttpRequest to url "translation.json" smile

27. November 2011, 19:31:56

stefanvd

Posts: 69

OK, just found JSOn to HTML code sample.
Thanks!

Forums » Dev.Opera » Opera Extensions Development Discussions