Custom Languages
Probably one of the most important aspects of any code is keeping it inline with your websites look, feel and language.
In FormLister, there are two solutions to adding your own bespoke language, Language folders containing individual files and Lexicons.
Solution 1 - Language Folder:
Take a look at the folder that contains all the language files, found here: "assets/snippets/FormLister/core/lang/"
Steps to take
1) Duplicate the folder named "english" (or any other language folder that you are capable of translating)
2) Rename it to your language of choice, e.g "german"
3) Now open all of the files that are in the folder.
In each file you have the information required for a specific situation, login, password etc.
Now all you need to do is translate the text found on each line.
Example (form.inc.php)
$_lang['form.protectSubmit'] = 'Message has been sent. There\'s no need to send it again'; $_lang['form.submitLimit'] = 'You may send message again in '; $_lang['form.minutes'] = 'min'; $_lang['form.seconds'] = 'sec'; $_lang['form.dateFormat'] = 'm.d.Y \a\t H:i:s'; $_lang['form.default_successTpl'] = '@CODE:Message was successfully sent [+form.date.value+]'; $_lang['form.form_failed'] = 'Message failed to send.';
$_lang['form.protectSubmit'] = 'TRANSLATE THIS'; $_lang['form.submitLimit'] = 'TRANSLATE THIS '; $_lang['form.minutes'] = 'TRANSLATE THIS'; $_lang['form.seconds'] = 'TRANSLATE THIS'; $_lang['form.dateFormat'] = 'm.d.Y \a\t H:i:s'; $_lang['form.default_successTpl'] = '@CODE:TRANSLATE THIS [+form.date.value+]'; $_lang['form.form_failed'] = 'TRANSLATE THIS.';
The result looks like this
$_lang['form.protectSubmit'] = 'Ihre Nachricht wurde gesendet, es besteht Keine Notwendigkeit es erneut zu senden'; $_lang['form.submitLimit'] = 'Sie können Ihre Nachricht erneut senden in '; $_lang['form.minutes'] = 'min'; $_lang['form.seconds'] = 'sek'; $_lang['form.dateFormat'] = 'd.m.Y \u\m H:i:s'; $_lang['form.default_successTpl'] = '@CODE:Ihre Nachricht wurde am [+form.date.value+] erfolgreich gesendet'; $_lang['form.form_failed'] = 'Ihre Nachricht konnte nicht gesendet werden.';
Once you have translated all of the files in the folder, save them and use the following parameter in your FormLister call.
&lang=`german`
Remember - the "lang" parameter must contain the exact same name you used for the folder, the name must be written exactly the same in both places.
Solution 2 - Language Lexicon:
This time we call the text directly in your FormLister call.
Important to note though, is the difference in structure - a "json" formatted call is used, in comparison to the files in the language folder, which use PHP.
For this example we use the standard form processing information, the information found in the "form.inc.php" file.
Copy the information that needs translating to your editor of choice:
$_lang['form.protectSubmit'] = 'Message has been sent. There\'s no need to send it again'; $_lang['form.submitLimit'] = 'You may send message again in '; $_lang['form.minutes'] = 'min'; $_lang['form.seconds'] = 'sec'; $_lang['form.dateFormat'] = 'm.d.Y \a\t H:i:s'; $_lang['form.default_successTpl'] = '@CODE:Message was successfully sent [+form.date.value+]'; $_lang['form.form_failed'] = 'Message failed to send.';
As we are now using json, we need to change how the code is formatted, the result looks like this:
"form.protectSubmit":"Message has been sent. There\\'s no need to send it again", "form.submitLimit":"You may send message again in ", "form.minutes":"min", "form.seconds":"sec", "form.dateFormat":"m.d.Y \\a\\t H:i:s", "form.default_successTpl":"@CODE:Message was successfully sent [+form.date.value+]", "form.form_failed":"Message failed to send."
Now it needs translating and adding to our FormLister call via the Lexicon parameter.
In this example we are using "german", so we need to make a ruleset for "german" in our lexicon parameter.
&lexicon=`{ "german":{ADD LANGUAGE INFORMATION HERE} }`
With the translated information, the complete call looks like this:
&lang=`german` &lexicon=`{ "german":{ "form.protectSubmit":"Ihre Nachricht wurde gesendet, es besteht Keine Notwendigkeit es erneut zu senden", "form.submitLimit":"Sie können Ihre Nachricht erneut senden in ", "form.minutes":"min", "form.seconds":"sek", "form.dateFormat":"d.m.Y \\u\\m H:i:s", "form.default_successTpl":"@CODE:Ihre Nachricht wurde am [+form.date.value+] erfolgreich gesendet", "form.form_failed":"Ihre Nachricht konnte nicht gesendet werden." } }`
Note that a "\" (backslash) in this format needs a second backslash, otherwise it won't work - for more information, check out the official json documentation.
We still define the "lang" parameter to our new language, otherwise it will take the default (english) and not use the new lexicon.
Closing Words
In both situations the result is the same, it is simply a matter of preferance which method you use.
If you use the folder method and update your website, ensure you remember to add the folder back into the site (depending on how you update).
Suggest an edit to this page.