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

  • String: FileLocation - Where all JSON files are stored
  • Function: Callback - function called when everything has been set.

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

  • String: FileLocation - Where all JSON files are stored
  • Function: Callback - function called when everything has been set.

VOID

Function called by the Init function it will load all languages files.

ChangeLanguage

  • Languages: Language - Define which language you want to set.

VOID

Will change the whole website language (It will update automatically, no page reload is required).

ChangeText

  • String: htmlID - Which block the text should be add.
  • String: langID - ID in the JSON files of your text.
  • String: langSection - Group in the JSON files where the langID is located.
  • String: defaultText - default text if Lang cannot find the specified langID

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

  • String: htmlID - Which block the text should be add.
  • String: langID - ID in the JSON files of your text.
  • String: langSection - Group in the JSON files where the langID is located.
  • String: defaultText - default text if Lang cannot find the specified langID

VOID

Same as ChangeText but it will apply to text inputs text-holder.

DeleteText

  • String: htmlID - Define where in the DOM the Lang should be unbind.


Unbind language from a specified HTML ID.


Note: Text will not be removed but will be updated.



Setters Functions

Name

Arguments

Return

Description

AddCallback

  • Function: CallbackFunc - Function to add

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

Languages

Languages.ENGLISH

Hold the active language.

data

JSON Class[]

[]

Hold all languages data structure. The array IDs match with the Language Enumerator.

defaultData

JSON Class

.

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

  • None

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

  • Boolean: NeedDefault - Define if it was the default data you require.

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