plugin translation

Post Reply
tdi
Jr. Bludit
Posts: 4
Joined: Fri Aug 13, 2021 2:05 pm

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.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
tdi
Jr. Bludit
Posts: 4
Joined: Fri Aug 13, 2021 2:05 pm

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.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Can you please send me the plugin.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
tdi
Jr. Bludit
Posts: 4
Joined: Fri Aug 13, 2021 2:05 pm

I've send you a mail. Thanks for having a look into it!
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
tdi
Jr. Bludit
Posts: 4
Joined: Fri Aug 13, 2021 2:05 pm

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.
Post Reply