https://github.com/richtr/opera-11-extensions--auto-i18n-library
Auto-translation library for Opera 11+ Extensions
https://github.com/richtr/opera-11-extensions--auto-i18n-library
Last synced: 9 months ago
JSON representation
Auto-translation library for Opera 11+ Extensions
- Host: GitHub
- URL: https://github.com/richtr/opera-11-extensions--auto-i18n-library
- Owner: richtr
- Created: 2010-12-20T09:01:06.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2010-12-28T16:27:22.000Z (over 15 years ago)
- Last Synced: 2025-04-03T19:19:32.874Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 129 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Auto Internationalization (I18N) Library for Opera Extensions
--------------------------------------------------------------
Written by Rich Tibbett.
Distributed under the Creative Commons Sharealike License:
http://creativecommons.org/licenses/by-sa/2.5/
The Auto I18N library for Opera 11+ extensions provides a convenient way for developers to
include multi-language support within their extensions without having to include those
translations manually.
This library creates an API at opera.extensions.i18n for developers to quickly and easily
add internationalization and localization support to their extensions.
A developer simply need write a single messages.js file, in the language of their choice,
and that will be localized according to their users' locales.
Follow these simple instructions to configure and use this library from
your Background, Popup and/or Injected Script processes:
--------------------------
Configuration
--------------------------
1. Add the following line to your configuration document (/config.xml):
2. Create your reference strings in /messages.js in the language of your choice. You can add
placeholders as in to which you can dynamically inject content at runtime as
required.
You may also use to indicate that you would not like 'your text' to be
translated in a given message. At run time, any <...!> syntax will be removed and replaced
with the inner text included.
See the included /messages.js file for format and examples.
Instructions for then using this library within your background process, popup process or
injected script processes are included below.
---------------
General Usage:
---------------
1. Include the following lines in your Background process (typically /index.html):
2. Copy and paste the /snippet.js file once at the *top* of each Popup or Injected Script
target file(s).
3. Access your localized messages by their *id* as follows within Javascript:
opera.extension.i18n.getMessage('welcomeMessage');
opera.extension.i18n.getMessage('helpButtonString');
// etc...
You can also replace placeholders in your messages at runtime as follows:
opera.extension.i18n.getMessage('somemessage', [ "string1", "string2" ]);
opera.extension.i18n.getMessage('sign_in_required_message', [
opera.extension.i18n.getMessage('sign_in_message')
]);
// etc...
That's all you need for complete auto-localization of your extension.
-------------------------------------
Using pre-defined translation files:
-------------------------------------
Opera 11+ Extensions support the W3C Widgets I18N model. This library is compatible with
this model and you may include pre-defined translations in the normal way.
If you have, for example, a pre-defined messages.js file that has been translated in to
French, you may include this in your extension within a /locales/fr/ directory.
Your extension will use any pre-defined locales files over any auto-translation capabilities
provided by this library.
For full details of the W3C Widgets I18N Model used in Opera extensions please consult the
spec at:
http://dev.w3.org/2006/waf/widgets/#internationalization-and-localization
------------------------
On-demand Translations:
------------------------
In addition to localizing your strings defined in your messages.js, this library can also
provide on-demand localization/translation for any messages you wish.
To use the on-demand localization feature, follow these instructions:
1. Once again, make sure that i18n_lib.js is included in your Background process page
(typically in index.html).
2. Copy and paste the /snippet.js file once at the *top* of each Popup or Injected Script
target file(s).
3. Perform on-demand translation/localization with the following code:
opera.extension.i18n.localize(
{
'mystring1': {
'message': 'string 1 to translate'
},
'mystring2': {
'message': 'string 2 to translate'
},
'mystring3': {
'message': 'string 3 to translate'
},
// include as many strings here as you like...
'somestring': {
'message': '...etc...'
}
},
// Translation callback function:
function( toLanguage, translatedStrings ) {
opera.postError('Translated messages to ' + toLanguage);
// Process resulting translations here...
// e.g. opera.extension.i18n.getMessage('mystring1');
}
);
4. Use the callback function to obtain the strings translated to the user's locale.
Alternatively use the standard I18N methods to obtain the translated messages:
opera.extension.i18n.getMessage('mystring1');
opera.extension.i18n.getMessage('somestring');
// ...etc...
You can also replace placeholders in your messages at runtime as follows:
opera.extension.i18n.getMessage('somemessage', [ "string1", "string2" ]);
opera.extension.i18n.getMessage('sign_in_required_message', [
opera.extension.i18n.getMessage('sign_in_message')
]);
// etc...
** NOTE******************************************************************************
** **
** IT IS QUICKER TO USE THE FIRST METHOD TO OBTAIN TRANSLATIONS. THE SECOND METHOD **
** SENDS AN INDIVIDUAL TRANSLATION REQUEST TO THE SERVERS EACH TIME THIS FUNCTION **
** IS CALLED. WHERE POSSIBLE YOU SHOULD PRE-DEFINE YOUR MESSAGES IN messages.js. **
** **
*************************************************************************************
--------
Support
--------
Any problems, questions or feedback please visit:
http://my.opera.com/richtr/blog/experimental-auto-internationalization-i18n-library-for-opera-11-extension-dev