浏览代码

feat(translations-cli): Fetch translations for a particular app (#17276)

* translataions for particular app 

get-untranslated/update-translations string for particular app frappe#17268 (feature request)

* fix: linting, making stuff DRY-er

Co-authored-by: gavin <gavin18d@gmail.com>
version-14
Danny 3 年前
committed by GitHub
父节点
当前提交
47483f833f
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 24 次插入10 次删除
  1. +6
    -4
      frappe/commands/translate.py
  2. +18
    -6
      frappe/translate.py

+ 6
- 4
frappe/commands/translate.py 查看文件

@@ -48,11 +48,12 @@ def new_language(context, lang_code, app):


@click.command("get-untranslated")
@click.option("--app", default="_ALL_APPS")
@click.argument("lang")
@click.argument("untranslated_file")
@click.option("--all", default=False, is_flag=True, help="Get all message strings")
@pass_context
def get_untranslated(context, lang, untranslated_file, all=None):
def get_untranslated(context, lang, untranslated_file, app="_ALL_APPS", all=None):
"Get untranslated strings for language"
import frappe.translate

@@ -60,17 +61,18 @@ def get_untranslated(context, lang, untranslated_file, all=None):
try:
frappe.init(site=site)
frappe.connect()
frappe.translate.get_untranslated(lang, untranslated_file, get_all=all)
frappe.translate.get_untranslated(lang, untranslated_file, get_all=all, app=app)
finally:
frappe.destroy()


@click.command("update-translations")
@click.option("--app", default="_ALL_APPS")
@click.argument("lang")
@click.argument("untranslated_file")
@click.argument("translated-file")
@pass_context
def update_translations(context, lang, untranslated_file, translated_file):
def update_translations(context, lang, untranslated_file, translated_file, app="_ALL_APPS"):
"Update translated strings"
import frappe.translate

@@ -78,7 +80,7 @@ def update_translations(context, lang, untranslated_file, translated_file):
try:
frappe.init(site=site)
frappe.connect()
frappe.translate.update_translations(lang, untranslated_file, translated_file)
frappe.translate.update_translations(lang, untranslated_file, translated_file, app=app)
finally:
frappe.destroy()



+ 18
- 6
frappe/translate.py 查看文件

@@ -808,7 +808,7 @@ def write_csv_file(path, app_messages, lang_dict):
w.writerow([message, translated_string, context])


def get_untranslated(lang, untranslated_file, get_all=False):
def get_untranslated(lang, untranslated_file, get_all=False, app="_ALL_APPS"):
"""Returns all untranslated strings for a language and writes in a file

:param lang: Language code.
@@ -816,11 +816,16 @@ def get_untranslated(lang, untranslated_file, get_all=False):
:param get_all: Return all strings, translated or not."""
clear_cache()
apps = frappe.get_all_apps(True)
if app != "_ALL_APPS":
if app not in apps:
print(f"Application {app} not found!")
return
apps = [app]

messages = []
untranslated = []
for app in apps:
messages.extend(get_messages_for_app(app))
for app_name in apps:
messages.extend(get_messages_for_app(app_name))

messages = deduplicate_messages(messages)

@@ -850,7 +855,7 @@ def get_untranslated(lang, untranslated_file, get_all=False):
print("all translated!")


def update_translations(lang, untranslated_file, translated_file):
def update_translations(lang, untranslated_file, translated_file, app="_ALL_APPS"):
"""Update translations from a source and target file for a given language.

:param lang: Language code (e.g. `en`).
@@ -879,9 +884,16 @@ def update_translations(lang, untranslated_file, translated_file):
translation_dict[restore_newlines(key)] = restore_newlines(value)

full_dict.update(translation_dict)
apps = frappe.get_all_apps(True)

for app in frappe.get_all_apps(True):
write_translations_file(app, lang, full_dict)
if app != "_ALL_APPS":
if app not in apps:
print(f"Application {app} not found!")
return
apps = [app]

for app_name in apps:
write_translations_file(app_name, lang, full_dict)


def import_translations(lang, path):


正在加载...
取消
保存