Make sure the following two lines are imported in your applet.js
file:
1 2 |
const GLib = imports.gi.GLib; const Gettext = imports.gettext; |
Add the following lines to your applet before function MyApplet(...)
:
1 2 3 4 5 6 7 8 9 10 |
// l10n/translation support const UUID = "yourApplet@You"; Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale"); function _(str) { return Gettext.dgettext(UUID, str); } function MyApplet(metadata, orientation, panelHeight, instance_id) { ...... |
And don't forget to change the const UUID
above to your applets UUID.
Every String in applet.js
you want to be translated, needs to be put in brackets with underscore _("")
, for example
1 |
_("This is a text, which needs to be translated") |
po
in the directory of your applet, where the metadata.json
file is saved.
metadata.json
file is saved.
cinnamon-xlet-makepot
The command creates a translation template file yourApplet.pot
in the po
directory.
Install the program "Poedit": sudo apt install poedit
Create new translation
.
yourApplet.pot
.
.po
file can be saved and the name will automatically reflect the locale code.
.mo
file saved, when you save your .po
file, the .mo
file should be deleted. You could also disable MO files creation from Poedit preferences (go to Edit > Preferences > General tab and uncheck the option called Automatically compile MO file when saving
).
metadata.json
file is saved.
cinnamon-xlet-makepot
The command overwrites yours translation template file yourApplet.pot
in the po
directory.
.po
file with Poedit.
Catalog
and choose the Update from POT file...
menu item.
yourApplet.pot
file from which your .po
file was based on.
The translations will be installed automatically, when the applet is installed through System Settings > Applets > Applet available (online)
.
If you have installed your applet manually and you want to test your translations:
metadata.json
file is saved.
cinnamon-xlet-makepot -i
to install the existing translations (i.e. the .po
files)
CTRL+ALT+ESC
If you want to remove your translations manually:
metadata.json
file is saved.
cinnamon-xlet-makepot -r
to remove the installed translations.
CTRL+ALT+ESC