Skip to content
Chris Hastie edited this page Jul 12, 2014 · 10 revisions

Translating the Weather Desklet

We need help to translate the Weather Desklet into other languages! If the messages from the desklet aren't available in your language, you could help!

Translating the Weather Desklet into your language

Messages in the Weather Desklet actually have two sources (see below). The instructions here are about translating the labels (eg 'Wind', 'Humidity') and units ('mph', '°C' etc), the text in the settings dialogue and forecasts from the BBC, Yahoo! and Weather.com.

Cinnamon desklets use gettext for translations. Language files are in the /po directory within the desklet. You will be creating a po file for your language, based on a template. The translation template is named [email protected].

You will need to create a file named [LOCALECODE].po where [LOCALECODE] is the code for your language and, optionally, area. For example, for Romanian you would create a file named ro.po in the /po directory, for Swiss German a file named de_CH.po. This file is initially a copy of the template, [email protected]. The simplest way to create your file is to use Poedit and the 'New catalog from POT file...' option. You can also create it with the msginit utility at the command line, for example, for Swiss German:

cd ~./local/share/cinnamon/desklets/[email protected]/po
msginit -o de_CH.po -l de_CH

It's easiest to use a utility such as Poedit to edit your translation. This will guide you through and you don't have to get to know the internals of a .po file.

Alternatively, you you can manually edit the file with your favourite text editor. Each entry consists of one or more comments (lines beginning #), followed by two parts. msgid identifies the messages and is (usually) the original English string, msgstr should contain your translation. An example in German:

#. # Days of the week
#: desklet.js:89
msgid "Mon"
msgstr "Mo"

As most of the strings are quite short it may not always be obvious what the context is, so I have tried to include comments to hint at this as much as possible. If you are using Poedit, make sure you have it set to display comments.

Please also note that wherever you see %s or %f you should not translate this, but include it as %s or %f in your translation. This will be substituted with some relevant value at runtime. A common use in the desklet is for units, eg

#. # wind speed, kilometers per hour
#: desklet.js:836
#, python-format
msgid "%fkm/h"
msgstr ""

%f might be substituted with '10' at runtime to produce '10km/h'. This is done to support languages that place units before, rather than after, the value, eg

msgid "%fkm/h"
msgstr "K%f"

would translate '10km/h' as 'K10'

I said msgid usually contains the original English. Unfortunately, not quite always. The msgids for units of temperature do not include the degree symbol (because it's not ASCII).

You will also need to edit the header appropriately - see the en_GB.po translation for an example. If you are using Poedit it will probably do this for you.

Don't feel you necessarily have to translate everything. If you can't manage the whole file I suggest focus on the labels from the desklet itself. Any messages that have msgstr left as an empty string will simply use the original English.

There is plenty more information on gettext and editing .po files to be found on the web.

Once your .po file is complete you can test it by switching to the desklet directory eg

cd ~/.local/share/cinnamon/desklets/[email protected]

and installing the translations with

cinnamon-json-makepot -i

You will probably need to restart Cinnamon to see the changes.

After testing, translations can be removed (this does not affect your .po file!) with

cinnamon-json-makepot -r

When you're happy with your translation, send your .po file to me, or create a pull request, and I can release it!

Where the messages come from

Here's a note about where the messages in the Weather Desklet come from...

Messages have two sources. The descriptive forecasts come from whichever service is providing the data (this depends on how you have configured the desklet). The labels, like 'Wind' and 'Humidity' come the desklet itself, as does all the text in the settings dialogue.

Some services provide translations of their forecasts into several languages. Where this is the case, the Weather Desklet will try to use them. It will check your preferred list of languages and request a forecast in the most preferred language that the service supports. Here's a list of the services that provide translations. Clicking on the link should take you to information about which languages are supported:

The other services supported by the desklet do not provide translated forecasts, but we've done our best to support translating the forecasts from these services within the desklet itself:

  • BBC
  • Yahoo!
  • Weather.com
Clone this wiki locally