bpy.app.translations.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. """
  2. Intro
  3. -----
  4. .. warning::
  5. Most of this object should only be useful if you actually manipulate i18n stuff from Python.
  6. If you are a regular add-on, you should only bother about :const:`contexts` member,
  7. and the :func:`register`/:func:`unregister` functions! The :func:`pgettext` family of functions
  8. should only be used in rare, specific cases (like e.g. complex "composited" UI strings...).
  9. | To add translations to your python script, you must define a dictionary formatted like that:
  10. | ``{locale: {msg_key: msg_translation, ...}, ...}``
  11. | where:
  12. - locale is either a lang iso code (e.g. ``fr``), a lang+country code (e.g. ``pt_BR``),
  13. a lang+variant code (e.g. ``sr@latin``), or a full code (e.g. ``uz_UZ@cyrilic``).
  14. - msg_key is a tuple (context, org message) - use, as much as possible, the predefined :const:`contexts`.
  15. - msg_translation is the translated message in given language!
  16. Then, call ``bpy.app.translations.register(__name__, your_dict)`` in your ``register()`` function, and
  17. ``bpy.app.translations.unregister(__name__)`` in your ``unregister()`` one.
  18. The ``Manage UI translations`` add-on has several functions to help you collect strings to translate, and
  19. generate the needed python code (the translation dictionary), as well as optional intermediary po files
  20. if you want some... See
  21. `How to Translate Blender <https://wiki.blender.org/wiki/Process/Translate_Blender>`_ and
  22. `Using i18n in Blender Code <https://wiki.blender.org/wiki/Source/Interface/Internationalization>`_
  23. for more info.
  24. Module References
  25. -----------------
  26. """
  27. import bpy
  28. # This block can be automatically generated by UI translations addon, which also handles conversion with PO format.
  29. # See also https://wiki.blender.org/wiki/Process/Translate_Blender#Translating_non-official_addons
  30. # It can (should) also be put in a different, specific py file.
  31. # ##### BEGIN AUTOGENERATED I18N SECTION #####
  32. # NOTE: You can safely move around this auto-generated block (with the begin/end markers!),
  33. # and edit the translations by hand.
  34. # Just carefully respect the format of the tuple!
  35. # Tuple of tuples ((msgctxt, msgid), (sources, gen_comments), (lang, translation, (is_fuzzy, comments)), ...)
  36. translations_tuple = (
  37. (("*", ""),
  38. ((), ()),
  39. ("fr_FR", "Project-Id-Version: Copy Settings 0.1.5 (r0)\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2013-04-18 15:27:45.563524\nPO-Revision-Date: 2013-04-18 15:38+0100\nLast-Translator: Bastien Montagne <montagne29@wanadoo.fr>\nLanguage-Team: LANGUAGE <LL@li.org>\nLanguage: __POT__\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n",
  40. (False,
  41. ("Blender's translation file (po format).",
  42. "Copyright (C) 2013 The Blender Foundation.",
  43. "This file is distributed under the same license as the Blender package.",
  44. "FIRST AUTHOR <EMAIL@ADDRESS>, YEAR."))),
  45. ),
  46. (("Operator", "Render: Copy Settings"),
  47. (("bpy.types.SCENE_OT_render_copy_settings",),
  48. ()),
  49. ("fr_FR", "Rendu : copier réglages",
  50. (False, ())),
  51. ),
  52. (("*", "Copy render settings from current scene to others"),
  53. (("bpy.types.SCENE_OT_render_copy_settings",),
  54. ()),
  55. ("fr_FR", "Copier les réglages de rendu depuis la scène courante vers d’autres",
  56. (False, ())),
  57. ),
  58. # ... etc, all messages from your addon.
  59. )
  60. translations_dict = {}
  61. for msg in translations_tuple:
  62. key = msg[0]
  63. for lang, trans, (is_fuzzy, comments) in msg[2:]:
  64. if trans and not is_fuzzy:
  65. translations_dict.setdefault(lang, {})[key] = trans
  66. # ##### END AUTOGENERATED I18N SECTION #####
  67. # Define remaining addon (operators, UI...) here.
  68. def register():
  69. # Usual operator/UI/etc. registration...
  70. bpy.app.translations.register(__name__, translations_dict)
  71. def unregister():
  72. bpy.app.translations.unregister(__name__)
  73. # Usual operator/UI/etc. unregistration...