From d9eb3274aaa6e1395c86c4dfaa488e493969857b Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 30 Nov 2009 16:51:15 +0000 Subject: LP 448319 : Translation layer tests and automatic generation of pot file (ongoing) --- (limited to 'tutorius/vault.py') diff --git a/tutorius/vault.py b/tutorius/vault.py index 1c1e33c..ef985fa 100644 --- a/tutorius/vault.py +++ b/tutorius/vault.py @@ -32,6 +32,7 @@ from ConfigParser import SafeConfigParser from . import addon from .tutorial import Tutorial, State, AutomaticTransitionEvent +from localization import LocalizationHelper logger = logging.getLogger("tutorius") @@ -60,6 +61,7 @@ INI_CATEGORY_PROPERTY = 'category' INI_FILENAME = "meta.ini" TUTORIAL_FILENAME = "tutorial.xml" RESOURCES_FOLDER = 'resources' +LOCALIZATION_FOLDER = 'localization' ###################################################################### # XML Tag names and attributes @@ -352,6 +354,12 @@ class Vault(object): with open(ini_file_path, 'wb') as configfile: parser.write(configfile) + l10n_path = os.path.join(tutorial_path, LOCALIZATION_FOLDER) + os.mkdir(l10n_path) + # Write the localization template (.pot) file + with open(os.path.join(l10n_path, 'tutorial_text.pot'), "wb") as l10n_file: + LocalizationHelper.write_translation_file(tutorial, l10n_file) + else: # Error, tutorial already exist return False @@ -528,6 +536,25 @@ class Vault(object): else: return None + @staticmethod + def get_localization_dir(tutorial_guid): + """ + Returns the base folder under which all the /LC_MESSAGES/tutorial_text.mo + are stored. These files are used for runtime translations by the Resource + Translator. + + @param tutorial_guid the guid of the tutorial + @returns the directory that stores the translation objects + """ + # Get the tutorial path + bundler = TutorialBundler(tutorial_guid) + tutorial_path = bundler.get_tutorial_path(tutorial_guid) + # Check if the localization directory exists + l10n_dir = os.path.join(tutorial_path, LOCALIZATION_FOLDER) + if os.path.isdir(l10n_dir): + return l10n_dir + else: + return None class Serializer(object): """ -- cgit v0.9.1