Scratchpad:Translation
From OpenLP
Contents |
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
- 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
- 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
- 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).
-
- We need to change the calls to addToolbarButton() in MediaManagerItem:
- Everything should be translatable
- unicode(translate('MediaManagerItem', 'Perform an action on %s')) % self.PluginItemName
- 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.
# openlp/core/lib/plugin.pyclass StringType(object):
Open = u'open'Load = u'load'Save = u'save'SaveAs = u'saveas'Import = u'import'Export = u'export'class Plugin(QtCore.QObject):
def __init__(...):
...
self.strings = {}
...
def getString(self, name):
if name in self.strings:
return self.strings[name]
else:# do something here?return None
# openlp/plugins/songs/songplugin.pyclass SongsPlugin(Plugin):
def __init__():
...
self.strings[StringType.Import] = {
u'title': translate('SongsPlugin', 'Import'),
u'tooltip': translate('SongsPlugin', 'Import songs')
}...
# openlp/core/lib/mediamanageritem.pyclass MediaManagerItem(QtGui.QWidget):
def __init__(self, parent=None, icon=None, title=None, plugin=None):
...
self.plugin = plugin
...
def addMiddleHeaderBar(self):
## Import Button ##if self.hasImportIcon:
importString = self.plugin.getString(StringType.Import)
self.addToolbarButton(
importString[u'title'],
importString[u'tooltip'],
u':/general/general_import.png', self.onImportClick)
...