We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The text was updated successfully, but these errors were encountered:
import json from pygtrans import Translate def load_json(file_path): with open(file_path, "r", encoding="utf-8") as file: return json.load(file) def extract_strings(data): strings = [] def _extract(_data): if isinstance(_data, dict): for key, value in _data.items(): _extract(value) elif isinstance(_data, list): for item in _data: _extract(item) elif isinstance(_data, str): strings.append(_data) _extract(data) return strings def replace_strings(data, dict_translated): def _replace(_data): if isinstance(_data, dict): for key, value in _data.items(): _data[key] = _replace(value) elif isinstance(_data, list): return [_replace(item) for item in _data] elif isinstance(_data, str): return dict_translated[_data] return _data return _replace(data) def save_json(data, file_path): with open(file_path, "w", encoding="utf-8") as file: json.dump(data, file, ensure_ascii=False, indent=4) def translate_json_file(input_file, output_file, target): data = load_json(input_file) strings = extract_strings(data) strings = list(set(strings)) strings_translated = at.translate(strings, target=target) dict_translated = {k: v.translatedText for k, v in zip(strings, strings_translated)} data_translated = replace_strings(data, dict_translated) save_json(data_translated, output_file) if __name__ == "__main__": at = Translate(fmt="text") translate_json_file("home_zh.json", "home_en.json", "en")
Sorry, something went wrong.
No branches or pull requests
一些可能常用的例子,欢迎大家参与
The text was updated successfully, but these errors were encountered: