sugarlabs/clock-activity

Name: clock-activity

Owner: Sugar Labs

Description: A nice clock for the Sugar learning environment

Created: 2015-05-08 19:04:54.0

Updated: 2017-05-30 03:58:22.0

Pushed: 2018-02-07 00:21:54.0

Homepage:

Size: 552

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

?# Clock activity

License

This activity and its code is put under public domain. Do whatever you want with it! If you want to contact me: Pierre Métras pierre@alterna.tv

Localization of the Clock

The code for the Clock activity is easily localizable to be used in Sugar with different languages and locales. To achieve that, we tried to put into gettext dictionnary all elements which could be culturally different, such as the fonts used to display texts in the clock. We also used Pango to have a better font management and give the translators the ability to adapt the display of text to their locale.

The Clock uses small messages. As with GUI software, it could be that the same messages have to be used in different contexts, and sometimes localized with different values (depending of the context). For instance, the font used to print the date in the Analog and Digital clock views are the same in the English/USA environment, but the font for the Digital one has to be reduced when using the Indi environment.

GNU gettext tool provides the pgettext() function to deal with such situations (see http://www.gnu.org/software/gettext/manual/gettext.html#Ambiguities). Sadly, the Python binding of gettext does not offer this function. I had to define a custom pgettext() and use it as a workaround, while we wait to have it included in a future Python version.

Note to translators: how to translate Pango markup?

Usage of Pango markup gives you a great deal of flexibility in the localization of the Clock activity. Let's take an example from the po/fr.po French localization file:

NS: datetime.strftime() format
o-python-format
txt "Digital Clock"
d "<markup><span lang=\"en\" font_desc=\"Sans Bold 80\">%x</span></markup>
tr "<markup><span lang=\"fr\" font_desc=\"Sans Bold 70\">%d %B %Y</span></markup>

First, I changed the language code from “en” to “fr”. Using the right language code let Pango determine the right rules for the layout of the text, for instance from right to left generally for Arabic.

Second, the “%x” format was not correctly supported by the internalization libraries on Build 653: it printed the date as “2008-03-26” instead of “26/03/2008” in French usage. So I decided to use a custom date layout to work around that bug. While at it, I decided that I would display the month name in full letters instead of the number of the month, like “26 mars 2008”, with the strftime format “%d %B %Y”.

After having changed the date format, I felt that some dates, like “31 octobre 2008” won't display correctly with all display orientations, and I went to reduce the font size from 80 pt to 70 pt. You could also decide to change the font family and use a better font instead of “Sans”.

Don't hesitate to adapt the Clock to your local needs…

Translation Wiki

For more information, please visit: Translation Wiki

The color codes to use:
Commands used to generate localized messages files

CAREFULL: _p() Python method is mapped to pgettext(msgctxt, msgstr).

The following procedure has to be done from a XO or a computer using UTF-8 as system encoding.

Clock$ is the prompt when I'm in the Clock directory.

First run
  1. Create the first messages template

    k$ xgettext --output=po/Clock.pot --add-comment --keyword=_p:1c,2 clock.py timewriter.py speaker.py
    
  2. Adapt po/Clock.pot file with author, copyright, etc.

    ock$ vi po/Clock.pot
    
  3. Initialize a new locale for French

    ock$ msginit --input=po/Clock.pot --output-file=po/fr.po --locale=fr
    
  4. Translate the messages in French

    k$ vi po/fr.po
    
  5. Create the binary messages file

    k$ msgfmt --output-file=locale/fr/LC_MESSAGES/tv.alterna.Clock.mo --check po/fr.po
    
Messages update

When the sources have changed

  1. Extract the new messages from the source like upper, in the po/Clock.pot file.

  2. Update a translated message file

    k$ $ msgmerge --update --backup=simple po/fr.po po/Clock.pot
    
  3. Translate the new messages and generate the binary file.

BUGS
POINT OF INTEREST IN THE CODE
TODO

A drop box for ideas. While the goal is to keep the source simple and understandable by Python starters, here are listed some ideas of features to include in the Clock activity to help learning how to read the time and have at the same time a usefull clock.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.