Page 1 of 1

plugin translation

Posted: Fri Aug 13, 2021 3:23 pm
by tdi
Hey everyone,

I'm relatively new to Bludit and was asked to write a simple plugin. Which in itself worked pretty good by looking at some other plugins. However I'm struggling with getting the admin panel labels for the plugins settings translated, even after googling around some time.

My understanding is, that I add the strings to the "languages/en.json" file and then access them in the plugin code. So if a "de.json" file was added, this can then include the translation of my labels. Lets add an minimal example.

languages/en.json

Code: Select all

{
    "plugin-data":
    {
        "name": "Nane of the Plugin",
        "description": "Some description"
    },
    "someVariableName": "The text that should be displayed"
}
and then later in the plugins code (plugin.php)

Code: Select all

    public function form()
    {
        global $L;
        
        ...
        $html .= '<div>';
        $html .= '<label>' . $L->get('someVariableName') . '</label>';
        $html .= '</div>';
        ...

        return $html;
    }
But instead of displaying The text that should be displayed the text someVariableName is displayed.

Any pointer directing me to the solution of the problem would be highly appreciated.

Re: plugin translation

Posted: Sat Aug 14, 2021 10:07 pm
by Edi
See for example the plugin Navigation:

https://github.com/bludit/bludit/tree/m ... navigation

In the file plugin.php there is for example (line 31):

Code: Select all

$html .= '<label>'.$L->get('Home link').'</label>';
In the language file en.json you can find the following line:

Code: Select all

"home-link": "Home link",
In the language file de_CH.json for example you can find the following line:

Code: Select all

"home-link": "Hauptseite zeigen",
$L->get('SomeText') in the file plugin.php displays "Some Text".

Therefore has always to be a file en.json with the pair "some-text": "Some text". some-text is in this case the name of the field, Some Text the value.

The other language files are "linked" with the name of the file en.json and display the value of the translation.

Is a word or a phrase already part of a translation of Bludit itself it has not to be added to the language files of the plugin.

Re: plugin translation

Posted: Sun Aug 15, 2021 2:06 pm
by tdi
Thanks for your reply Edi!

So I've changed the code according to your notes, now the EN original text is displayed :) however the German translation is not picked up. The rest of the admin panel is showing up in German, but not the strings I've translated for the plugin. Neither does my translation of the

Code: Select all

plugin-data -> description
.

I've tried

Code: Select all

de.json
and

Code: Select all

de_DE.json
as filename for the translation. Neither seems to be picked up.

Re: plugin translation

Posted: Sun Aug 15, 2021 4:34 pm
by Edi
Can you please send me the plugin.

Re: plugin translation

Posted: Mon Aug 16, 2021 10:07 am
by tdi
I've send you a mail. Thanks for having a look into it!

Re: plugin translation

Posted: Mon Aug 16, 2021 12:25 pm
by Edi
Only the English language file has the name en.json. All translations have names like de_DE.json, fr_FR.json etc. (ICU locale with language and country code).

If there are special characters the language file has to be saved as UTF-8.

I sent you back the modified language files.

Re: plugin translation

Posted: Fri Sep 03, 2021 12:00 pm
by tdi
Thanks again for your help Edi!

Just to have it written out somewhere ;) an addition problem arose from me linking my development directory into the servers Bludit directory, so that the translations were not picked up.