Lang
The Lang classes will be used to handle language through your website or web app. It will use a single JSON file, read all and update all yours texts so can easily translate your whole website.
How to Initialize the Lang?
The initialization of the Lang is an one step process, just call the function Init of the class with its two arguments (see bellow for more details).
Class Details
Functions:
Initialization & Main Functions
Name |
Arguments |
Return |
Description |
Init |
|
VOID |
This function will try to get where the user is located to set a default languages (Cookies has to be handle the external code). Once done it will call the InitText function. |
InitText |
|
VOID |
Function called by the Init function it will load all languages files. |
ChangeLanguage |
|
VOID |
Will change the whole website language (It will update automatically, no page reload is required). |
ChangeText |
|
VOID |
This is the main function of this class, with this you will be able to add your text into your website. This function will look for the text in selected language file : FILE->GROUP->LANG_ID If nothing was found it will look in the default text file (English). And if not text was it will use defaultText as text. All the data will be stored into binders class, will updated at each Update(). Note: everything that is in the defined htmlID is deleted at each update |
ChangeTextHolder |
|
VOID |
Same as ChangeText but it will apply to text inputs text-holder. |
DeleteText |
|
Unbind language from a specified HTML ID. Note: Text will not be removed but will be updated. |
Setters Functions
Name |
Arguments |
Return |
Description |
AddCallback |
|
VOID |
Add another callback function (can add infinite amount). The function are called when texts are updated. Note: this functionality is often use when an update modify something that JS need correct each change. |
Private Details
All private details are usable but its recommended to not use any of those. It might modify the proper functioning of the class.
Variables (Members):
Name |
Type |
Default Value |
Description |
language |
Hold the active language. |
||
data |
[] |
Hold all languages data structure. The array IDs match with the Language Enumerator. |
|
defaultData |
. |
Hold the default languages data structure (English). Used for backup. |
|
bindedList |
Binder[] |
[] |
List of all the binders. |
callbackList |
Function[] |
[] |
Hold the list of all callback that UpdateText need to call |
Functions:
Update
Name |
Arguments |
Return |
Description |
UpdateText |
|
VOID |
Will go trough all binders and update all texted (it delete and rewrite content). At the function end it will call all callbacks. |
Accessor
Name |
Arguments |
Return |
Description |
GetData |
|
VOID |
Send back the data or defaultData. |
JSON Data
The JSON Files are define by they name
EN.json = ENGLISH
FR.json = FRENCH
Here is a sum/example of the JSON Structure:
{
"Section1": [
{
"LineID" : "LangID1",
"Line" : "Text1"
},
{
"LineID" : "LangID2",
"Line" : "Text"
}
],
"Example": [
{
"LineID" : "ExampleLine",
"Line" : "Example Text"
},
{
"LineID" : "Test_Line",
"Line" : "This is a test line."
}
]
}
Compatibility
LANGUAGE CLASS: N/A
Created with the Personal Edition of HelpNDoc: Free help authoring tool