Example #1
0
    """
    with open(file, "w") as f:
        for string in strings:
            f.write('msgid "{0}"\nmsgstr ""\n\n'.format(string))
        
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Extract strings from objective-c files")
    parser.add_argument("-d", "--directory", default=".", help="directory to scan")
    parser.add_argument("-o", "--output", default="untranslated.txt", help="destination filename")
    parser.add_argument("-p", "--pot", help="existing pot file")

    args = parser.parse_args()

    # get filenames
    files = build_file_list(args.directory)

    # get strings from source code
    regex = re.compile("_\(@\"(.+)\"\)")
    strings = []
    for file in files:
        result = extract_string(file, regex)
        if result:
            strings.extend(result)
    
    # remove duplicates string
    strings = remove_duplicate(strings)

    # remove already translated strings
    strings = remove_already_in_pot(strings, args.pot)
Example #2
0
def convert(files, dst):
    for file in files:
        basename = os.path.basename(file)
        root, ext = os.path.splitext(basename)

        dst_dir = os.path.join(dst, root + ".lproj")
        if not os.path.exists(dst_dir):
            os.makedirs(dst_dir)
            print "Creating directory {0}".format(dst_dir)

        print "Converting {0} to {1}".format(file, os.path.join(dst_dir, "Localizable.strings"))
        po2strings.convert_file(file, os.path.join(dst_dir, "Localizable.strings"))


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Convert all po files to Xcode localized version")
    parser.add_argument("-s", "--source", help="directory containing po files",
            required=True)
    parser.add_argument("-o", "--output",  help="Xcode destination directory",
            required=True)

    args = parser.parse_args()

    files = ftree.build_file_list(args.source, ".po")
    convert(files, args.output)
    files = ftree.build_file_list(args.source, ".pot")
    convert(files, args.output)