Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Auto-translation library for Opera 11+ Extensions

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 includes
Octocat-spinner-32 README
Octocat-spinner-32 config.xml
Octocat-spinner-32 i18n_lib.js
Octocat-spinner-32 index.html
Octocat-spinner-32 messages.js
Octocat-spinner-32 popup.html
Octocat-spinner-32 snippet.js
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):
 
 		<access origin="https://ajax.googleapis.com" />
 
 2. Create your reference strings in /messages.js in the language of your choice. You can add 
    placeholders as <string/> in to which you can dynamically inject content at runtime as 
    required. 
    
    You may also use <your text!> 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):
 
 		<script type="text/javascript" src="messages.js"></script>
 		<script type="text/javascript" src="i18n_lib.js"></script>
 
 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 <string/> 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).
 
 		<script type="text/javascript" src="i18n_lib.js"></script>
 
 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 <string/> 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
Something went wrong with that request. Please try again.