25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

110 satır
2.6 KiB

  1. import click
  2. from frappe.commands import get_site, pass_context
  3. from frappe.exceptions import SiteNotSpecifiedError
  4. # translation
  5. @click.command("build-message-files")
  6. @pass_context
  7. def build_message_files(context):
  8. "Build message files for translation"
  9. import frappe.translate
  10. for site in context.sites:
  11. try:
  12. frappe.init(site=site)
  13. frappe.connect()
  14. frappe.translate.rebuild_all_translation_files()
  15. finally:
  16. frappe.destroy()
  17. if not context.sites:
  18. raise SiteNotSpecifiedError
  19. @click.command("new-language") # , help="Create lang-code.csv for given app")
  20. @pass_context
  21. @click.argument("lang_code") # , help="Language code eg. en")
  22. @click.argument("app") # , help="App name eg. frappe")
  23. def new_language(context, lang_code, app):
  24. """Create lang-code.csv for given app"""
  25. import frappe.translate
  26. if not context["sites"]:
  27. raise Exception("--site is required")
  28. # init site
  29. frappe.connect(site=context["sites"][0])
  30. frappe.translate.write_translations_file(app, lang_code)
  31. print(
  32. "File created at ./apps/{app}/{app}/translations/{lang_code}.csv".format(
  33. app=app, lang_code=lang_code
  34. )
  35. )
  36. print(
  37. "You will need to add the language in frappe/geo/languages.json, if you haven't done it already."
  38. )
  39. @click.command("get-untranslated")
  40. @click.argument("lang")
  41. @click.argument("untranslated_file")
  42. @click.option("--all", default=False, is_flag=True, help="Get all message strings")
  43. @pass_context
  44. def get_untranslated(context, lang, untranslated_file, all=None):
  45. "Get untranslated strings for language"
  46. import frappe.translate
  47. site = get_site(context)
  48. try:
  49. frappe.init(site=site)
  50. frappe.connect()
  51. frappe.translate.get_untranslated(lang, untranslated_file, get_all=all)
  52. finally:
  53. frappe.destroy()
  54. @click.command("update-translations")
  55. @click.argument("lang")
  56. @click.argument("untranslated_file")
  57. @click.argument("translated-file")
  58. @pass_context
  59. def update_translations(context, lang, untranslated_file, translated_file):
  60. "Update translated strings"
  61. import frappe.translate
  62. site = get_site(context)
  63. try:
  64. frappe.init(site=site)
  65. frappe.connect()
  66. frappe.translate.update_translations(lang, untranslated_file, translated_file)
  67. finally:
  68. frappe.destroy()
  69. @click.command("import-translations")
  70. @click.argument("lang")
  71. @click.argument("path")
  72. @pass_context
  73. def import_translations(context, lang, path):
  74. "Update translated strings"
  75. import frappe.translate
  76. site = get_site(context)
  77. try:
  78. frappe.init(site=site)
  79. frappe.connect()
  80. frappe.translate.import_translations(lang, path)
  81. finally:
  82. frappe.destroy()
  83. commands = [
  84. build_message_files,
  85. get_untranslated,
  86. import_translations,
  87. new_language,
  88. update_translations,
  89. ]