# Copyright (C) 2009, Tutorius.org # Copyright (C) 2009, Michael Janelle-Montcalm # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os class LocalizationHelper(object): @classmethod def _write_addon_strings_to_file(cls, addon, output_file): """ For a given addon, writes a pot file entry for every string property it has. @param addon The addon from which we want to get the string properties @param output_file The file in which we should write the strings @return None """ for (prop_name, prop_value) in addon._props.items(): prop_type = getattr(type(addon), prop_name).type if prop_type == "string": prop_value = prop_value.replace("\n", "\\n") prop_value = prop_value.replace("\r", "\\r") output_file.write('msgid "%s"\nmsgstr ""\n\n'%(prop_value)) @classmethod def write_translation_file(cls, tutorial, output_file): """ Writes the translation file to the given file, according to the .pot files specifications, for the given tutorial. This will generate a pair of line for each TStringProperty in the following format : msgid "" msgstr "" This will enable the translator to create a localization for this tutorial. @param tutorial The executable reprensentation of the @param output_file An opened file object to which the strings translation template will be written @return Nothing """ state_dict = tutorial.get_state_dict() for state_name in state_dict.keys(): actions = tutorial.get_action_dict(state_name) events = tutorial.get_transition_dict(state_name) for action in actions.values(): cls._write_addon_strings_to_file(action, output_file) for (event, next_state) in events.values(): cls._write_addon_strings_to_file(event, output_file)