You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 regels
2.6 KiB

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