Exemplo n.º 1
0
def load_messages(lang=None):
    if lang is None: lang = language

    g.messages.clear()

    files = dirs.get_readable_i18n_files("messages.po", lang, default_language=False)

    for lang, pofile in files:
        try:
            po = polib.pofile(pofile)
            for entry in po.translated_entries():
                g.messages[entry.msgid] = entry.msgstr
        except IOError: pass # silently ignore non-existing files
Exemplo n.º 2
0
def load_messages(lang=None):
    if lang is None: lang = language

    messages.clear()

    files = dirs.get_readable_i18n_files("messages.po", lang, default_language=False)

    for lang, pofile in files:
        try:
            po = polib.pofile(pofile)
            for entry in po.translated_entries():
                messages[entry.msgid] = entry.msgstr
        except IOError: pass # silently ignore non-existing files
Exemplo n.º 3
0
def load_story_defs():
    global story
    story = {}

    story_files = dirs.get_readable_i18n_files("story_str.dat", language)

    if len(story_files) == 0:
        print "Story is missing. Skipping."
        return

    # Take the last story file, story is never partially translated.
    story_file = open(story_files[-1][1])

    section_name = ""
    segment = ""
    line_num = 1

    for raw_line in story_file.readlines():
        line = raw_line.decode("utf-8")

        if line and line != "\n":
            if line[0] == "#":
                pass  # Ignore comment
            elif line[0] == "[":
                if line[-2] == "]":
                    section_name = line[1:-2]
                    story[section_name] = []
                else:
                    sys.stderr.write(
                        "Line start with [ and is not a section at line %d.\n"
                        % line_num)
            elif line[0] == "|":
                segment += line[1:]
            else:
                # TODO: Parse command
                sys.stderr.write("Invalid command at line %d.\n" % line_num)
        else:
            if segment:
                story[section_name].append(segment)
                segment = ""

        line_num += 1

    # Add last segment.
    if segment:
        story[section_name].append(segment)
Exemplo n.º 4
0
def load_story_defs(lang=None):
    story = g.story = {}
    
    story_files = dirs.get_readable_i18n_files("story_str.dat", lang)
    
    if len(story_files) == 0:
        print "Story is missing. Skipping."
        return
        
    # Take the last story file, story is never partially translated.
    story_file = open(story_files[-1][1])

    section_name = ""
    segment = ""
    line_num = 1;

    for raw_line in story_file.readlines():
        line = raw_line.decode("utf-8")
        
        if line and line != "\n":
            if line[0] == "#":
                pass # Ignore comment
            elif line[0] == "[":
                if line[-2] == "]":
                    section_name = line[1:-2]
                    story[section_name] = []
                else:
                    sys.stderr.write("Line start with [ and is not a section at line %d.\n" % line_num)
            elif line[0] == "|":
                segment += line[1:]
            else:
                # TODO: Parse command
                sys.stderr.write("Invalid command at line %d.\n" % line_num)
        else:
            if segment:
                story[section_name].append(segment)
                segment = ""
                
        line_num += 1

    # Add last segment.
    if segment:
        story[section_name].append(segment)
Exemplo n.º 5
0
def load_generic_defs_file(name,lang=None):
    import i18n
    
    return_list = []

    i18n_files = dirs.get_readable_i18n_files(name + "_str.dat", lang)

    for lang, filepath in i18n_files:
        # Definition file for default language is always mandatory
        mandatory = (lang==i18n.default_language)

        try:
            mandatory = (lang==i18n.default_language)
            return_list.extend( generic_load(filepath, mandatory=mandatory) )

        except Exception:
            pass # For other languages, ignore errors

    return return_list
Exemplo n.º 6
0
def load_generic_defs_file(name, lang=None):
    if lang is None: lang = language

    return_list = []

    i18n_files = dirs.get_readable_i18n_files(name + "_str.dat", lang)

    for lang, filepath in i18n_files:
        # Definition file for default language is always mandatory
        mandatory = (lang == default_language)

        try:
            mandatory = (lang == default_language)
            return_list.extend(generic_load(filepath, mandatory=mandatory))

        except Exception:
            pass  # For other languages, ignore errors

    return return_list
Exemplo n.º 7
0
def get_intro():
    intro_files = dirs.get_readable_i18n_files("intro_str.dat", language)

    if len(intro_files) == 0:
        print "Intro is missing.  Skipping."
        return

    # Take the last intro file, intro is never partially translated.
    intro_file = open(intro_files[-1][1])
    raw_intro = intro_file.readlines() + [""]

    segment = ""
    while raw_intro:
        line = raw_intro.pop(0).decode("utf-8")
        if line and line[0] == "|":
            segment += line[1:]
        elif segment:
            yield segment
            segment = ""

    if segment:
        yield segment