So I've created Moodle plugin which has 2 localization. In the plugin's form, I have a selector which is translated according to the chosen localization. I wonder if I do this, will cause the stored information on the database mixed? If it does, is there a method to ensure the database will be saved in only 1 language, or if I should translate it in the script before storing it, or even create a translated database altogether? Thanks in advance!
CodePudding user response:
It would have been better if you had explained more about the use of the dropdown menu and database details. by the way, let's assume that you need to create a menu to select a job title from among different titles. These job titles are stored in a table with id and title columns. In your frontend client can see the job titles in their local language and choose the desired option, and finally, you will save the id associated with the selected job title into a database table along with other input values that come from your HTML form.
<datalist>
<option name='job' value="id-1">developer</option>
<option name='job' value="id-2">HR</option>
....
</datalist>
CodePudding user response:
Moodle already has localisation. If you want display text in different languages, then you need to add a file in your plugin for that language.
In your code you would use a string tag
$options = array();
$options[1] = get_string('optionone', 'my_plugin')
$options[2] = get_string('optiontwo', 'my_plugin')
You will also need a language file for English as the default
File location
my_plugin/lang/en/my_plugin.php
Then add the string tags
$string['optionone'] = 'Option One';
$string['optiontwo'] = 'Option Two';
Then you can add more languages eg
my_plugin/lang/fr/my_plugin.php
$string['optionone'] = 'Option Un';
$string['optiontwo'] = 'Option Deux';
For more details see