Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Zverev <zverik@textual.ru>2017-06-16 19:31:44 +0300
committerVladimir Byko-Ianko <bykoianko@gmail.com>2017-06-29 14:06:21 +0300
commit4968355df1ecaed19f4b0e33a938acf80239545f (patch)
tree9a697e2c6a20bae6c43fe31870c604fab4e76c5a /tools/python
parent41e6abc095d39bbc7cf674da433f388bb72b87db (diff)
[tts] Refactor TTS translations
Diffstat (limited to 'tools/python')
-rwxr-xr-xtools/python/tts_languages.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tools/python/tts_languages.py b/tools/python/tts_languages.py
new file mode 100755
index 0000000000..e9ac929115
--- /dev/null
+++ b/tools/python/tts_languages.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+from __future__ import print_function
+from optparse import OptionParser
+import re
+
+LANGUAGES_HPP_TEMPLATE = """\
+#pragma once
+
+#include "std/array.hpp"
+#include "std/string.hpp"
+
+// This file is autogenerated while exporting sounds.csv from the google table.
+// It contains the list of languages which can be used by TTS.
+// It shall be included to Android(jni) and iOS part to get the languages list.
+
+namespace routing
+{{
+namespace turns
+{{
+namespace sound
+{{
+array<string, {lang_list_size}> const kLanguageList =
+{{{{
+{lang_list}
+}}}};
+}} // namespace sound
+}} // namespace turns
+}} // namespace routing
+"""
+
+
+def parse_args():
+ opt_parser = OptionParser(
+ description="Creates a language.hpp out of the sound.txt file.",
+ usage="python %prog <path_to_sound.txt> <path_to_languages.hpp>",
+ version="%prog 1.0"
+ )
+ (options, args) = opt_parser.parse_args()
+ if len(args) != 2:
+ opt_parser.error("Wrong number of arguments.")
+ return args
+
+
+def read_languages(strings_name):
+ langs = set()
+ RE_LANG = re.compile(r'^ *([\w-]+) *=')
+ with open(strings_name, "r") as langs_file:
+ for line in langs_file:
+ m = RE_LANG.search(line)
+ if m:
+ langs.add(m.group(1))
+ return langs
+
+
+def make_languages_hpp(langs, hpp_name):
+ print ("Creating {}".format(hpp_name))
+ lang_str = ",\n".join([" \"{}\"".format(language) for language in sorted(langs)])
+ with open(hpp_name, "w") as hpp_file:
+ hpp_file.write(LANGUAGES_HPP_TEMPLATE.format(lang_list_size=len(langs), lang_list=lang_str))
+
+
+def run():
+ strings_name, langs_hpp_name = parse_args()
+ langs = read_languages(strings_name)
+ make_languages_hpp(langs, langs_hpp_name)
+
+
+if __name__ == "__main__":
+ run()