Please enhance chrome.i18n: Replace __MSG_*__ in the HTML, too.

704 views
Skip to first unread message

Edward Gerhold

unread,
Feb 24, 2011, 2:11:51 PM2/24/11
to Chromium-extensions
Has that to be? I haven´t tried it out until today.

If i want to write a multilingual extension, the current status of
chrome.i18n does not satisfy my needs. I have two problems.

The first one is, that the "message" strings from the message.json
files can only be inserted by using Javascript. __MSG_*__ is only
recognized in the manifest.json file.

It would be cool, if the HTML files could have the __MSG_*__ tags,
like Gadgets have.

The second problem is that writing larger texts, like a paragraph p,
require a very long "message" string in the messages.json file. It can
´t be written over multiple lines like a regular paragraph in a
document can be.

Is that correct? Isn´t there a requirement for the replacement of
__MSG_*__ in the HTML documents, too? Having to insert each text by
script, and then with the long string problem of the json format,
where i can´t simply press return within the text, makes it
uncomfortable to write multilingual extensions, or?

I would like to have at last __MSG_*__ parsed from the HTML. The
second with the string is just a consideration. But the problem, that
i have to use script for each message, is too uncomfortable for me. Is
there anything speaking against the replacement of __MSG_*__ also in
the HTML document?

Edward

Michael Gundlach

unread,
Mar 1, 2011, 10:53:57 AM3/1/11
to Edward Gerhold, Chromium-extensions
Hi Edward,

See localizePage() in http://code.google.com/p/adblockforchrome/source/browse/trunk/functions.js .  You can call that in a <script> at the bottom of your page, and it localizes the HTML for you.  You'll need to include jQuery on the page as well.

The syntax for the HTML markup is:

<div i18n="some_i18n_message"/>
 - This div's content will be replaced with the value of some_i18n_message
 - It can be used on any HTML element, including <input type='button'>
 - $1-$9 placeholders are not supported.

There is also advanced support for replacing elements on the fly with the i18n_replacement_el attribute, but you probably won't need that for most cases.

The code is GPL.  Have at it, and I hope this helps!

- Michael


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Edward Gerhold

unread,
Mar 2, 2011, 1:21:51 AM3/2/11
to Chromium-extensions
Wow, that is a great idea. I would like to point to the translate
function above localizePage() for any other, to see, how easy it is,
to fetch the appropriate message. I will use your code next time i´m
writing on the extension. Possibly i´ll write that with Javascript
again, because i haven´t learned jQuery until today. jQuery is my
favourite library i haven´t learned, but which i will, somewhen. We´ll
see when. But next time, i write on the extensions, i´ll take time to
implement your solution. Because it is great. I know that this will
run later. And i thank you very very much for the answer. Great
idea!!! Thanks!

Edward

P.S. Dear chromium developers, Michael gave me what i wanted, but i
would like to state again, that native support for the messages in the
HTML would be useful for any other programmer and all, having not read
this post, searching for such a method. I have the solution now from
him, but anyone else would have to search for again. Could you please
add the replacement of the messages in the HTML to make it easy like
in the gadgets with the message bundles, where i could write __MSG_*__
anywhere???

Mike West

unread,
Mar 2, 2011, 5:50:16 AM3/2/11
to Edward Gerhold, Chromium-extensions
Hi Edward,

It's correct that the `i18n` API only supports direct substitutions in
manifest.json and CSS files. http://crbug.com/68467 is a bug
requesting for the HTML replacement functionality you're describing,
but I don't believe there are any plans to implement it in the near
future. Starring that bug would be the best way to keep track of any
updates in the future.

In the meantime, `localizePage` which Michael posted looks
interesting, and I've done similar (though simpler) work that simply
walks through an HTML page, and uses the `i18n` API to do
replacements. See
https://github.com/mikewest/Instapaper-Chrome-Extension/blob/master/sendtoinstapaper.js#L240
and https://github.com/mikewest/Instapaper-Chrome-Extension/blob/master/sendtoinstapaper.js#L286-290

Thanks!

-Mike

> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.
> For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
>

- West <mk...@google.com>
Developer Advocate
Google Germany GmbH, Dienerstrasse 12, 80331 München, Germany
Cell: +49 162 10 255 91, Twitter: @mikewest

Reply all
Reply to author
Forward
0 new messages