
Originally Posted by
liang3391
How do I give this plug-in the establishment of regional languages do?
This currently involves manual editing of files via the command line. As part of our revamping of the language system beginning in 11.25, we intend to eventually introduce official locale support for plugins (Internal Case 32966). In the meantime, you can follow these instructions to allow your plugin to display a different label based on the language selected for the cPanel interface:
1. Open up the file generated by our plugin generator in your preferred text editor. Change the text after itemdesc: to $LANG{mylangkey} where mylangkey can be almost any alphanumeric string without spaces. This is what we call a "language key." Language keys help us look up phrases in language files (more on that later).
So, instead of something like:
Code:
...
#cpanelif tag (just the stuff inside <cpanelif> not the tag>
if:
#Text to display in cpanel
itemdesc:Plugin by DavidG
#order to display the item in cpanel
itemorder:999
...
We now have something like:
Code:
...
#cpanelif tag (just the stuff inside <cpanelif> not the tag>
if:
#Text to display in cpanel
itemdesc:$LANG{davidg}
#order to display the item in cpanel
itemorder:999
...
If this plugin has already been installed, uninstall it.
Now, install this plugin.
2. When you look in cPanel, you'll probably see a "language key not found" error under your plugin. That's expected. Let's go ahead and create that language key.
Language keys are stored in what we call language files. When you want to add your own language keys to the system, you create a .local file. For example, to create your own language keys for the english-utf8 language file, you would create a file called english-utf8.local. You would place this file in /usr/local/cpanel/lang/ so this key is available to all cPanel themes.
Language files have a simple format of key=value on each line. Since I'm only creating 1 new language key (in my example, davidg), my /usr/local/cpanel/lang/english-utf8.local file that I created has this as its contents:
Code:
davidg=Plugin by DavidG
I then repeat this process for each language I want to translate this phrase into. For example, I would create /usr/local/cpanel/lang/chinese.local if I wanted to have this message displayed in Chinese. The key (on the left side of =) stays the same, but the value (on the right side of =) changes to be whatever the phrase is translated as, in the other language.
3. To apply these changes, run the following command via SSH:
/usr/local/cpanel/bin/cleancachelangfiles
4. If you still get language key errors or your language keys fail to update when you change them, I've found clearing the contents of /var/cpanel/lang.cache/ then running the above command helps the situation.
If you need to display which language is currently selected within your plugin, the following API1 code will display the currently selected language:
HTML Code:
<cpanel print="$CPDATA{'LANG'}">