Download

Concepts

Example

Documentation

Plugins

How to

Contribute

Links

LangManager

What is this ?

This is the class that will take care of the lang management. This is a singleton class. So you will call it using LangManager.geInstance(). If you want to use the langManager with dynamically loaded file, don't forget to set useLang to true in your framework configuration file.

Lang files

Name your lang configuration file

Your lang files will have to be in the langFolder as defined in your framework configuration file. The name of the file has to be the lang that will be in it. It also have the extension (langFileExtension) as defined in the framework configuration file.

<?xml version="1.0" encoding="utf-8"?>
<items>
	<framework>
		<url>
			<item baseUrl="http://localhost/js/" />		
			<item addBaseUrl="true" />
		</url>
		<folder>
			<item langFolder="lang/" />
			...
		</folder>
		...
		<lang>
			<item useLang="true" />
			<item langFileExtension="conf" />
			<item defaultLang="fr_FR" />
			<item langParseMethod="flat" />
			<item lang="fr_FR" />
		</lang>
		...
	</framework>
	...
</items>		

So here, you will at least have a file call fr_FR.conf in http://localhost/js/lang/

What is in a lang file ?

Depending on the langParseMethod you choose (flat or xml), you can have :

If you are choosing flat :
KEY = value1
KEY_2 = toto
KEY_3 = tyty

If you are choosing xml :
<?xml version="1.0" encoding="utf-8"?>
<items>
	<item KEY="value1" />		
	<item KEY_2="toto" />
	<item KEY_3="tyty" />
</items>		

How do I know that the lang changed ?

You will know it by using the langChangeHandler() method of your model helper.

LangManager methods

add(key, value, lang)

Sometimes, you will want to add lang value even if you are not using a lang file. So you will use this method. Example :

In the framework configuration file :
...	
<item useLang="false" />
<item defaultLang="en_EN" />
...

In your HTML file :
<head>
	...
	<script type="text/javascript" src="http://localhost/js/WZFwk/libs/prototype/1.6.0.3.js"></script>
	<script type="text/javascript" src="http://localhost/js/WZFwk/libs/prototype/extends.js"></script>
	<script type="text/javascript" src="http://localhost/js/WZFwk/compress/compress.js"></script>
	<script type="text/javascript">
		var initializer = new Initializer();
		initializer.init("http://localhost/js/application/conf.xml");
		
		LangManager.getInstance().add("MY_KEY", "my value", "en_EN");
		LangManager.getInstance().add("MY_KEY", "ma valeur", "fr_FR");
	</script>
	...
</head>

In a model helper :
var ModuleModel = Class.create(ModelHelper, {
	...
	langChangeHandler: function(newLang) {
		alert(LangManager.getInstance().get('MY_KEY')); // --> ma valeur
	},
	...
	myFunction: function() {
		alert(LangManager.getInstance().get('MY_KEY')); // --> my value
		LangManager.getInstance().setLang('fr_FR');
	},
	...
});

Take also a look to the init() method of your model helper.

setLang(lang)

If you wish to change the lang in your application, you will use this method. The LangManager will load the file corresponding to the new lang, execute bindings and launch langChangeHandler. in the modelHelpers listening to the lang change event.

get(key)

Will return the value corresponding to the key inside the lang file.

getLang()

Will return the current lang.