Initial multi-language support

This commit is contained in:
Et0h 2014-06-29 20:56:18 +01:00
parent 9cbb290ef2
commit 88e7de39b7
3 changed files with 65 additions and 45 deletions

View File

@ -40,6 +40,7 @@ NSIS_SCRIPT_TEMPLATE = r"""
VIAddVersionKey /LANG=$${LANG_POLISH} "LegalCopyright" "Syncplay"
VIAddVersionKey /LANG=$${LANG_POLISH} "FileDescription" "Syncplay"
LangString ^SyncplayLanguage $${LANG_ENGLISH} "en"
LangString ^Associate $${LANG_ENGLISH} "Associate Syncplay with multimedia files."
LangString ^VLC $${LANG_ENGLISH} "Install Syncplay interface for VLC 2 and above"
LangString ^BrowseVLCBtn $${LANG_ENGLISH} "Select VLC folder"
@ -49,6 +50,7 @@ NSIS_SCRIPT_TEMPLATE = r"""
LangString ^QuickLaunchBar $${LANG_ENGLISH} "Quick Launch Bar"
LangString ^UninstConfig $${LANG_ENGLISH} "Delete configuration file."
LangString ^SyncplayLanguage $${LANG_POLISH} "pl"
LangString ^Associate $${LANG_POLISH} "Skojarz Syncplaya z multimediami"
LangString ^VLC $${LANG_POLISH} "Zainstaluj interface Syncplaya dla VLC 2+"
LangString ^BrowseVLCBtn $${LANG_POLISH} "Określ folder VLC"
@ -158,7 +160,7 @@ NSIS_SCRIPT_TEMPLATE = r"""
Push $${LANG_POLISH}
Push Polski
Push A ; A means auto count languages
LangDLL::LangDialog "Installer Language" "Please select the language of the installer"
LangDLL::LangDialog "Language Selection" "Please select the language of Syncplay and the installer"
Pop $$LANGUAGE
StrCmp $$LANGUAGE "cancel" 0 +2
Abort
@ -398,6 +400,7 @@ NSIS_SCRIPT_TEMPLATE = r"""
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "NoRepair" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "EstimatedSize" "$$SizeHex"
WriteINIStr $$APPDATA\syncplay.ini general language $$(^SyncplayLanguage)
FunctionEnd
Function un.installConfirm

View File

@ -102,6 +102,7 @@ en = {
"file-argument" : 'file to play',
"args-argument" : 'player options, if you need to pass options starting with - prepend them with single \'--\' argument',
"clear-gui-data-argument" : 'resets path and window state GUI data stored as QSettings',
"language-argument" :'language for Syncplay messages (en/pl)',
# Client labels
"config-window-title" : "Syncplay configuration",
@ -249,45 +250,49 @@ en = {
pl = {
# Client notifications
"connection-attempt-notification" : "Próba połączenia z {}:{}", # Port, IP
"reconnection-attempt-notification" : "Połączenie z serwerem zostało przerwane, ponowne łączenie",
"disconnection-notification" : "Odłączono od serwera",
"connection-failed-notification" : "Połączenie z serwerem zakończone fiaskiem",
"connection-attempt-notification" : u"Próba połączenia z {}:{}", # Port, IP
"reconnection-attempt-notification" : u"Połączenie z serwerem zostało przerwane, ponowne łączenie",
"disconnection-notification" : u"Odłączono od serwera",
"connection-failed-notification" : u"Połączenie z serwerem zakończone fiaskiem",
"rewind-notification" : "Cofnięto z powodu różnicy czasu z <{}>", # User
"slowdown-notification" : "Zwolniono z powodu różnicy czasu z <{}>", # User
"revert-notification" : "Przywrócono normalną prędkość odtwarzania",
"rewind-notification" : u"Cofnięto z powodu różnicy czasu z <{}>", # User
"slowdown-notification" : u"Zwolniono z powodu różnicy czasu z <{}>", # User
"revert-notification" : u"Przywrócono normalną prędkość odtwarzania",
"pause-notification" : "<{}> zatrzymał odtwarzanie", # User
"unpause-notification" : "<{}> wznowił odtwarzanie", # User
"seek-notification" : "<{}> skoczył z {} do {}", # User, from time, to time
"pause-notification" : u"<{}> zatrzymał odtwarzanie", # User
"unpause-notification" : u"<{}> wznowił odtwarzanie", # User
"seek-notification" : u"<{}> skoczył z {} do {}", # User, from time, to time
"current-offset-notification" : "Obecny offset: {} seconds", # Offset
"current-offset-notification" : u"Obecny offset: {} seconds", # Offset
"room-join-notification" : "<{}> dołączył do pokoju: '{}'", # User
"left-notification" : "<{}> wyszedł", # User
"playing-notification" : "<{}> odtwarza '{}' ({})", # User, file, duration
"playing-notification/room-addendum" : " w pokoju: '{}'", # Room
"room-join-notification" : u"<{}> dołączył do pokoju: '{}'", # User
"left-notification" : u"<{}> wyszedł", # User
"playing-notification" : u"<{}> odtwarza '{}' ({})", # User, file, duration
"playing-notification/room-addendum" : u" w pokoju: '{}'", # Room
"file-different-notification" : "Plik, który odtwarzasz wydaje się być różny od <{}>", # User
"file-differences-notification" : "Twój plik różni się następującymi parametrami: ",
"file-different-notification" : u"Plik, który odtwarzasz wydaje się być różny od <{}>", # User
"file-differences-notification" : u"Twój plik różni się następującymi parametrami: ",
"different-filesize-notification" : " (inny rozmiar pliku!)",
"file-played-by-notification" : "Plik: {} jest odtwarzany przez:", # File
"notplaying-notification" : "Osoby, które nie odtwarzają żadnych plików:",
"userlist-room-notification" : "W pokoju '{}':", # Room
"different-filesize-notification" : u" (inny rozmiar pliku!)",
"file-played-by-notification" : u"Plik: {} jest odtwarzany przez:", # File
"notplaying-notification" : u"Osoby, które nie odtwarzają żadnych plików:",
"userlist-room-notification" : u"W pokoju '{}':", # Room
# Client prompts
"enter-to-exit-prompt" : "Wciśnij Enter, aby zakończyć działanie programu\n",
"enter-to-exit-prompt" : u"Wciśnij Enter, aby zakończyć działanie programu\n",
# Client errors
"server-timeout-error" : "Przekroczono czas oczekiwania na odpowiedź serwera"
"server-timeout-error" : u"Przekroczono czas oczekiwania na odpowiedź serwera"
}
messages = {
"en": en,
"pl": pl
"pl": pl,
"current": ""
}
def setLanguage(lang):
messages["current"] = lang
def getMessage(locale, type_):
if(constants.SHOW_BUTTON_LABELS == False):
if("-guibuttonlabel" in type_):
@ -295,6 +300,10 @@ def getMessage(locale, type_):
if(constants.SHOW_TOOLTIPS == False):
if("-tooltip" in type_):
return ""
lang = messages["current"]
if(messages.has_key(lang)):
if(messages[lang].has_key(type_)):
return unicode(messages[lang][type_])
if(messages.has_key(locale)):
if(messages[locale].has_key(type_)):
return unicode(messages[locale][type_])

View File

@ -3,7 +3,7 @@ import argparse
import os
import sys
from syncplay import constants, utils
from syncplay.messages import getMessage
from syncplay.messages import getMessage, setLanguage
from syncplay.players.playerFactory import PlayerFactory
import codecs
try:
@ -40,7 +40,8 @@ class ConfigurationGetter(object):
"filenamePrivacyMode": constants.PRIVACY_SENDRAW_MODE,
"filesizePrivacyMode": constants.PRIVACY_SENDRAW_MODE,
"pauseOnLeave": False,
"clearGUIData": False
"clearGUIData": False,
"language" : ""
}
#
@ -67,26 +68,9 @@ class ConfigurationGetter(object):
self._iniStructure = {
"server_data": ["host", "port", "password"],
"client_settings": ["name", "room", "playerPath", "slowdownThreshold", "rewindThreshold", "slowMeOnDesync", "dontSlowDownWithMe", "forceGuiPrompt", "filenamePrivacyMode", "filesizePrivacyMode", "pauseOnLeave"],
"general": ["language"]
}
#
# Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments
#
self._argparser = argparse.ArgumentParser(description=getMessage("en", "argument-description"),
epilog=getMessage("en", "argument-epilog"))
self._argparser.add_argument('--no-gui', action='store_true', help=getMessage("en", "nogui-argument"))
self._argparser.add_argument('-a', '--host', metavar='hostname', type=str, help=getMessage("en", "host-argument"))
self._argparser.add_argument('-n', '--name', metavar='username', type=str, help=getMessage("en", "name-argument"))
self._argparser.add_argument('-d', '--debug', action='store_true', help=getMessage("en", "debug-argument"))
self._argparser.add_argument('-g', '--force-gui-prompt', action='store_true', help=getMessage("en", "force-gui-prompt-argument"))
self._argparser.add_argument('--no-store', action='store_true', help=getMessage("en", "no-store-argument"))
self._argparser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help=getMessage("en", "room-argument"))
self._argparser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help=getMessage("en", "password-argument"))
self._argparser.add_argument('--player-path', metavar='path', type=str, help=getMessage("en", "player-path-argument"))
self._argparser.add_argument('file', metavar='file', type=str, nargs='?', help=getMessage("en", "file-argument"))
self._argparser.add_argument('--clear-gui-data', action='store_true', help=getMessage("en", "clear-gui-data-argument"))
self._argparser.add_argument('_args', metavar='options', type=str, nargs='*', help=getMessage("en", "args-argument"))
self._playerFactory = PlayerFactory()
def _validateArguments(self):
@ -281,18 +265,42 @@ class ConfigurationGetter(object):
def getConfiguration(self):
iniPath = self._getConfigurationFilePath()
self._parseConfigFile(iniPath)
#
# Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments
#
if self._config['language']:
setLanguage(self._config['language'])
self._argparser = argparse.ArgumentParser(description=getMessage("en", "argument-description"),
epilog=getMessage("en", "argument-epilog"))
self._argparser.add_argument('--no-gui', action='store_true', help=getMessage("en", "nogui-argument"))
self._argparser.add_argument('-a', '--host', metavar='hostname', type=str, help=getMessage("en", "host-argument"))
self._argparser.add_argument('-n', '--name', metavar='username', type=str, help=getMessage("en", "name-argument"))
self._argparser.add_argument('-d', '--debug', action='store_true', help=getMessage("en", "debug-argument"))
self._argparser.add_argument('-g', '--force-gui-prompt', action='store_true', help=getMessage("en", "force-gui-prompt-argument"))
self._argparser.add_argument('--no-store', action='store_true', help=getMessage("en", "no-store-argument"))
self._argparser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help=getMessage("en", "room-argument"))
self._argparser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help=getMessage("en", "password-argument"))
self._argparser.add_argument('--player-path', metavar='path', type=str, help=getMessage("en", "player-path-argument"))
self._argparser.add_argument('--language', metavar='language', type=str, help=getMessage("en", "language-argument"))
self._argparser.add_argument('file', metavar='file', type=str, nargs='?', help=getMessage("en", "file-argument"))
self._argparser.add_argument('--clear-gui-data', action='store_true', help=getMessage("en", "clear-gui-data-argument"))
self._argparser.add_argument('_args', metavar='options', type=str, nargs='*', help=getMessage("en", "args-argument"))
args = self._argparser.parse_args()
self._overrideConfigWithArgs(args)
if(self._config['file'] and self._config['file'][:2] == "--"):
self._config['playerArgs'].insert(0, self._config['file'])
self._config['file'] = None
# Arguments not validated yet - booleans are still text values
if self._config['language']:
setLanguage(self._config['language'])
if(self._config['forceGuiPrompt'] == "True" or not self._config['file']):
self._forceGuiPrompt()
self._checkConfig()
self._saveConfig(iniPath)
if(self._config['file']):
self._config['loadedRelativePaths'] = self._loadRelativeConfiguration()
if self._config['language']:
setLanguage(self._config['language'])
if(not self._config['noGui']):
from syncplay.vendor import qt4reactor
if QCoreApplication.instance() is None: