Scratchpad:Translation

From OpenLP
Jump to: navigation, search

Translation Roadmap

General Notes

(more for developers) Please use the translate() method from openlp/core/lib/__init__.py, rather than self.trUtf8(), because self.trUtf8() is not always able to detect the correct translation context (especially on Windows).

Status

  1. Static Translation (In progress)
    • Framework Done
    • Correct Translation context (Ongoing)
    • Open Issues
      • Plugin Names are not be translated yet
      • Plugin Names in the plugin window (Alt+F7) are not be translated yet
      • Names of Bible chapters are not translated yet
  2. Dynamic Translation
    • Framework
    • Side Effects
      • in toolbar.py -> addToolbarButton(...) the list self.icons[] is built with the translated titles, so after language is changes all the content is invalid :-(

Steps to fixing translation issues

Why translation of contexts for each plugin have to be done

some plugin names need different genders: e.g.: "a bible", "une bible" "a song", "un chant" "an alert", "une alerte"

May there are languages which have different word order? ...


Way for imlementation

  1. We need to declare additional variables:
    • plugin.name: The internal name of the plugin
    • plugin.displayName: The translatable name of the plugin
    • plugin.itemName: The name of the item this plugin provides (also translatable)
    • plugin.itemNamePlural: The plural of the item name (translatable).
  2. We need to change the calls to addToolbarButton() in MediaManagerItem:
    • Everything should be translatable
    • unicode(translate('MediaManagerItem', 'Perform an action on %s')) % self.PluginItemName
  3. We need to pass in names from the plugin:
    • internal name, display name, item name, section name
    • perhaps use a dict?



Example Plugin 3

This is the revised version.

 1 # openlp/core/lib/plugin.py
 2 
 3 class StringType(object):
 4     Open = u'open'
 5     Load = u'load'
 6     Save = u'save'
 7     SaveAs = u'saveas'
 8     Import = u'import'
 9     Export = u'export'
10 
11 class Plugin(QtCore.QObject):
12     def __init__(...):
13         ...
14         self.strings = {}
15         ...
16 
17     def getString(self, name):
18         if name in self.strings:
19             return self.strings[name]
20         else:
21             # do something here?
22             return None
23 
24 # openlp/plugins/songs/songplugin.py
25 
26 class SongsPlugin(Plugin):
27     def __init__():
28         ...
29         self.strings[StringType.Import] = {
30             u'title': translate('SongsPlugin', 'Import'),
31             u'tooltip': translate('SongsPlugin', 'Import songs')
32         }
33         ...
34 
35 # openlp/core/lib/mediamanageritem.py
36 
37 class MediaManagerItem(QtGui.QWidget):
38     def __init__(self, parent=None, icon=None, title=None, plugin=None):
39         ...
40         self.plugin = plugin
41         ...
42 
43     def addMiddleHeaderBar(self):
44         ## Import Button ##
45         if self.hasImportIcon:
46             importString = self.plugin.getString(StringType.Import)
47             self.addToolbarButton(
48                 importString[u'title'],
49                 importString[u'tooltip'],
50                 u':/general/general_import.png', self.onImportClick)
51         ...