Blender  V3.3
Classes | Macros
bpy_app_translations.c File Reference
#include <Python.h>
#include <structmember.h>
#include "BLI_utildefines.h"
#include "BPY_extern.h"
#include "bpy_app_translations.h"
#include "MEM_guardedalloc.h"
#include "BLT_lang.h"
#include "BLT_translation.h"
#include "RNA_types.h"
#include "../generic/python_utildefines.h"

Go to the source code of this file.

Classes

struct  BlenderAppTranslations
 

Macros

#define SetObjString(item)    PyStructSequence_SET_ITEM(translations_contexts, pos++, PyUnicode_FromString((item)))
 
#define SetObjNone()    PyStructSequence_SET_ITEM(translations_contexts, pos++, Py_INCREF_RET(Py_None))
 

Functions

Helpers for GHash
 PyDoc_STRVAR (app_translations_py_messages_register_doc, ".. method:: register(module_name, translations_dict)\n" "\n" " Registers an addon's UI translations.\n" "\n" " .. note::\n" " Does nothing when Blender is built without internationalization support.\n" "\n" " :arg module_name: The name identifying the addon.\n" " :type module_name: string\n" " :arg translations_dict: A dictionary built like that:\n" " ``{locale: {msg_key: msg_translation, ...}, ...}``\n" " :type translations_dict: dict\n" "\n")
 
static PyObject * app_translations_py_messages_register (BlenderAppTranslations *self, PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (app_translations_py_messages_unregister_doc, ".. method:: unregister(module_name)\n" "\n" " Unregisters an addon's UI translations.\n" "\n" " .. note::\n" " Does nothing when Blender is built without internationalization support.\n" "\n" " :arg module_name: The name identifying the addon.\n" " :type module_name: string\n" "\n")
 
static PyObject * app_translations_py_messages_unregister (BlenderAppTranslations *self, PyObject *args, PyObject *kw)
 

Variables

Local Struct to Store Translation
static BlenderAppTranslations_translations = NULL
 

C-defined Contexts

static PyTypeObject BlenderAppTranslationsContextsType
 
static BLT_i18n_contexts_descriptor _contexts [] = BLT_I18NCONTEXTS_DESC
 
static PyStructSequence_Field app_translations_contexts_fields [ARRAY_SIZE(_contexts)] = {{NULL}}
 
static PyStructSequence_Desc app_translations_contexts_desc
 
static PyObject * app_translations_contexts_make (void)
 

Main #BlenderAppTranslations #PyObject Definition

static PyMemberDef app_translations_members []
 
static PyGetSetDef app_translations_getseters []
 
static PyMethodDef app_translations_methods []
 
static PyTypeObject BlenderAppTranslationsType
 
 PyDoc_STRVAR (app_translations_contexts_doc, "A named tuple containing all predefined translation contexts.\n" "\n" ".. warning::\n" " Never use a (new) context starting with \"" BLT_I18NCONTEXT_DEFAULT_BPYRNA "\", it would be internally\n" " assimilated as the default one!\n")
 
 PyDoc_STRVAR (app_translations_contexts_C_to_py_doc, "A readonly dict mapping contexts' C-identifiers to their py-identifiers.")
 
 PyDoc_STRVAR (app_translations_locale_doc, "The actual locale currently in use (will always return a void string when Blender " "is built without " "internationalization support).")
 
static PyObject * app_translations_locale_get (PyObject *UNUSED(self), void *UNUSED(userdata))
 
 PyDoc_STRVAR (app_translations_locales_doc, "All locales currently known by Blender (i.e. available as translations).")
 
static PyObject * app_translations_locales_get (PyObject *UNUSED(self), void *UNUSED(userdata))
 
static PyObject * _py_pgettext (PyObject *args, PyObject *kw, const char *(*_pgettext)(const char *, const char *))
 
 PyDoc_STRVAR (app_translations_pgettext_doc, ".. method:: pgettext(msgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt).\n" "\n" " .. note::\n" " The ``(msgid, msgctxt)`` parameters order has been switched compared to gettext " "function, to allow\n" " single-parameter calls (context then defaults to BLT_I18NCONTEXT_DEFAULT).\n" "\n" " .. note::\n" " You should really rarely need to use this function in regular addon code, as all " "translation should be\n" " handled by Blender internal code. The only exception are string containing formatting " "(like \"File: %r\"),\n" " but you should rather use :func:`pgettext_iface`/:func:`pgettext_tip` in those cases!\n" "\n" " .. note::\n" " Does nothing when Blender is built without internationalization support (hence always " "returns ``msgid``).\n" "\n" " :arg msgid: The string to translate.\n" " :type msgid: string\n" " :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt: string or None\n" " :return: The translated string (or msgid if no translation was found).\n" "\n")
 
static PyObject * app_translations_pgettext (BlenderAppTranslations *UNUSED(self), PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (app_translations_pgettext_iface_doc, ".. method:: pgettext_iface(msgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt), if labels' translation " "is enabled.\n" "\n" " .. note::\n" " See :func:`pgettext` notes.\n" "\n" " :arg msgid: The string to translate.\n" " :type msgid: string\n" " :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt: string or None\n" " :return: The translated string (or msgid if no translation was found).\n" "\n")
 
static PyObject * app_translations_pgettext_iface (BlenderAppTranslations *UNUSED(self), PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (app_translations_pgettext_tip_doc, ".. method:: pgettext_tip(msgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt), if tooltips' " "translation is enabled.\n" "\n" " .. note::\n" " See :func:`pgettext` notes.\n" "\n" " :arg msgid: The string to translate.\n" " :type msgid: string\n" " :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt: string or None\n" " :return: The translated string (or msgid if no translation was found).\n" "\n")
 
static PyObject * app_translations_pgettext_tip (BlenderAppTranslations *UNUSED(self), PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (app_translations_pgettext_data_doc, ".. method:: pgettext_data(msgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt), if new data name's " "translation is enabled.\n" "\n" " .. note::\n" " See :func:`pgettext` notes.\n" "\n" " :arg msgid: The string to translate.\n" " :type msgid: string\n" " :arg msgctxt: The translation context (defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt: string or None\n" " :return: The translated string (or ``msgid`` if no translation was found).\n" "\n")
 
static PyObject * app_translations_pgettext_data (BlenderAppTranslations *UNUSED(self), PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (app_translations_locale_explode_doc, ".. method:: locale_explode(locale)\n" "\n" " Return all components and their combinations of the given ISO locale string.\n" "\n" " >>> bpy.app.translations.locale_explode(\"sr_RS@latin\")\n" " (\"sr\", \"RS\", \"latin\", \"sr_RS\", \"sr@latin\")\n" "\n" " For non-complete locales, missing elements will be None.\n" "\n" " :arg locale: The ISO locale string to explode.\n" " :type msgid: string\n" " :return: A tuple ``(language, country, variant, language_country, language@variant)``.\n" "\n")
 
static PyObject * app_translations_locale_explode (BlenderAppTranslations *UNUSED(self), PyObject *args, PyObject *kw)
 
static PyObject * app_translations_new (PyTypeObject *type, PyObject *UNUSED(args), PyObject *UNUSED(kw))
 
static void app_translations_free (void *obj)
 
 PyDoc_STRVAR (app_translations_doc, "This object contains some data/methods regarding internationalization in Blender, " "and allows every py script\n" "to feature translations for its own UI messages.\n" "\n")
 
PyObject * BPY_app_translations_struct (void)
 
void BPY_app_translations_end (void)
 

Detailed Description

This file defines a singleton py object accessed via 'bpy.app.translations', which exposes various data and functions useful in i18n work. Most notably, it allows to extend main translations with py dicts.

Definition in file bpy_app_translations.c.

Macro Definition Documentation

◆ SetObjNone

#define SetObjNone ( )     PyStructSequence_SET_ITEM(translations_contexts, pos++, Py_INCREF_RET(Py_None))

◆ SetObjString

#define SetObjString (   item)     PyStructSequence_SET_ITEM(translations_contexts, pos++, PyUnicode_FromString((item)))

Function Documentation

◆ _py_pgettext()

static PyObject* _py_pgettext ( PyObject *  args,
PyObject *  kw,
const char *(*)(const char *, const char *)  _pgettext 
)
static

◆ app_translations_contexts_make()

static PyObject* app_translations_contexts_make ( void  )
static

◆ app_translations_free()

static void app_translations_free ( void obj)
static

Definition at line 761 of file bpy_app_translations.c.

◆ app_translations_locale_explode()

static PyObject* app_translations_locale_explode ( BlenderAppTranslations UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 669 of file bpy_app_translations.c.

References BLT_lang_locale_explode(), MEM_SAFE_FREE, and NULL.

◆ app_translations_locale_get()

static PyObject* app_translations_locale_get ( PyObject *  UNUSEDself,
void UNUSEDuserdata 
)
static

Definition at line 481 of file bpy_app_translations.c.

References BLT_lang_get().

◆ app_translations_locales_get()

static PyObject* app_translations_locales_get ( PyObject *  UNUSEDself,
void UNUSEDuserdata 
)
static

◆ app_translations_new()

static PyObject* app_translations_new ( PyTypeObject *  type,
PyObject *  UNUSEDargs,
PyObject *  UNUSEDkw 
)
static

◆ app_translations_pgettext()

static PyObject* app_translations_pgettext ( BlenderAppTranslations UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 581 of file bpy_app_translations.c.

References _py_pgettext(), and BLT_pgettext().

◆ app_translations_pgettext_data()

static PyObject* app_translations_pgettext_data ( BlenderAppTranslations UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 647 of file bpy_app_translations.c.

References _py_pgettext(), and BLT_translate_do_new_dataname().

◆ app_translations_pgettext_iface()

static PyObject* app_translations_pgettext_iface ( BlenderAppTranslations UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 603 of file bpy_app_translations.c.

References _py_pgettext(), and BLT_translate_do_iface().

◆ app_translations_pgettext_tip()

static PyObject* app_translations_pgettext_tip ( BlenderAppTranslations UNUSEDself,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 625 of file bpy_app_translations.c.

References _py_pgettext(), and BLT_translate_do_tooltip().

◆ app_translations_py_messages_register()

static PyObject* app_translations_py_messages_register ( BlenderAppTranslations self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 306 of file bpy_app_translations.c.

References NULL, self, and void.

◆ app_translations_py_messages_unregister()

static PyObject* app_translations_py_messages_unregister ( BlenderAppTranslations self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 359 of file bpy_app_translations.c.

References NULL, self, and void.

◆ BPY_app_translations_end()

void BPY_app_translations_end ( void  )

Definition at line 891 of file bpy_app_translations.c.

Referenced by BPY_python_end().

◆ BPY_app_translations_struct()

PyObject* BPY_app_translations_struct ( void  )

◆ PyDoc_STRVAR() [1/12]

PyDoc_STRVAR ( app_translations_contexts_C_to_py_doc  ,
"A readonly dict mapping contexts' C-identifiers to their py-identifiers."   
)

◆ PyDoc_STRVAR() [2/12]

PyDoc_STRVAR ( app_translations_contexts_doc  ,
"A named tuple containing all predefined translation contexts.\n" "\n" ".. warning::\n" " Never use a (new) context starting with \"" BLT_I18NCONTEXT_DEFAULT_BPYRNA "\"  ,
it would be internally\n" " assimilated as the default one!\n"   
)

◆ PyDoc_STRVAR() [3/12]

PyDoc_STRVAR ( app_translations_doc  ,
"This object contains some data/methods regarding internationalization in  Blender,
" "and allows every py script\n" "to feature translations for its own UI messages.\n" "\n"   
)

◆ PyDoc_STRVAR() [4/12]

PyDoc_STRVAR ( app_translations_locale_doc  ,
"The actual locale currently in use (will always return a void string when Blender " "is built without " "internationalization support)."   
)

◆ PyDoc_STRVAR() [5/12]

PyDoc_STRVAR ( app_translations_locale_explode_doc  ,
".. method:: locale_explode(locale)\n" "\n" " Return all components and their combinations of the given ISO locale string.\n" "\n" " >>  ,
bpy.app.translations.locale_explode(\"sr_RS@latin\")\n" " (\"sr\", \"RS\", \"latin\", \"sr_RS\", \"sr@latin\")\n" "\n" " For non-complete  locales,
missing elements will be None.\n" "\n" " :arg locale:The ISO locale string to explode.\n" " :type msgid:string\n" " :return:A tuple ``(language, country, variant, language_country, language @variant)``.\n" "\n"   
)

◆ PyDoc_STRVAR() [6/12]

PyDoc_STRVAR ( app_translations_locales_doc  ,
"All locales currently known by Blender (i.e. available as translations)."   
)

◆ PyDoc_STRVAR() [7/12]

PyDoc_STRVAR ( app_translations_pgettext_data_doc  ,
".. method::   pgettext_datamsgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt,
if new data name 's " "translation is enabled.\n" "\n" " .. note::\n" " See :func:`pgettext` notes.\n" "\n" " :arg msgid:The string to translate.\n" " :type msgid:string\n" " :arg msgctxt:The translation context(defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt:string or None\n" " :return:The translated string(or ``msgid`` if no translation was found).\n" "\n"   
)

◆ PyDoc_STRVAR() [8/12]

PyDoc_STRVAR ( app_translations_pgettext_doc  ,
".. method:: pgettext(msgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt).\n" "\n" " .. note::\n" " The ``(msgid, msgctxt)`` parameters order has been switched compared to gettext " "  function,
to allow\n" " single-parameter calls(context then defaults to BLT_I18NCONTEXT_DEFAULT).\n" "\n" " .. note::\n" " You should really rarely need to use this function in regular addon  code,
as all " "translation should be\n" " handled by Blender internal code. The only exception are string containing formatting " "  like \"File: %r\",
\n" " but you should rather use :func:`pgettext_iface`/:func:`pgettext_tip` in those cases!\n" "\n" " .. note::\n" " Does nothing when Blender is built without internationalization support(hence always " "returns ``msgid``).\n" "\n" " :arg msgid:The string to translate.\n" " :type msgid:string\n" " :arg msgctxt:The translation context(defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt:string or None\n" " :return:The translated string(or msgid if no translation was found).\n" "\n"   
)

◆ PyDoc_STRVAR() [9/12]

PyDoc_STRVAR ( app_translations_pgettext_iface_doc  ,
".. method::   pgettext_ifacemsgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt,
if labels' translation " "is enabled.\n" "\n" " .. note::\n" " See :func:`pgettext` notes.\n" "\n" " :arg msgid:The string to translate.\n" " :type msgid:string\n" " :arg msgctxt:The translation context(defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt:string or None\n" " :return:The translated string(or msgid if no translation was found).\n" "\n"   
)

◆ PyDoc_STRVAR() [10/12]

PyDoc_STRVAR ( app_translations_pgettext_tip_doc  ,
".. method::   pgettext_tipmsgid, msgctxt=None)\n" "\n" " Try to translate the given msgid (with optional msgctxt,
if tooltips' " "translation is enabled.\n" "\n" " .. note::\n" " See :func:`pgettext` notes.\n" "\n" " :arg msgid:The string to translate.\n" " :type msgid:string\n" " :arg msgctxt:The translation context(defaults to BLT_I18NCONTEXT_DEFAULT).\n" " :type msgctxt:string or None\n" " :return:The translated string(or msgid if no translation was found).\n" "\n"   
)

◆ PyDoc_STRVAR() [11/12]

PyDoc_STRVAR ( app_translations_py_messages_register_doc  ,
".. method:: register(module_name, translations_dict)\n" "\n" " Registers an addon's UI translations.\n" "\n" " .. note::\n" " Does nothing when Blender is built without internationalization support.\n" "\n" " :arg module_name: The name identifying the addon.\n" " :type module_name: string\n" " :arg translations_dict: A dictionary built like that:\n" " ``{locale: {msg_key: msg_translation, ...}, ...}``\n" " :type translations_dict: dict\n" "\n"   
)

◆ PyDoc_STRVAR() [12/12]

PyDoc_STRVAR ( app_translations_py_messages_unregister_doc  ,
".. method:: unregister(module_name)\n" "\n" " Unregisters an addon's UI translations.\n" "\n" " .. note::\n" " Does nothing when Blender is built without internationalization support.\n" "\n" " :arg module_name: The name identifying the addon.\n" " :type module_name: string\n" "\n"   
)

Variable Documentation

◆ _contexts

◆ _translations

BlenderAppTranslations* _translations = NULL
static

Definition at line 54 of file bpy_app_translations.c.

Referenced by app_translations_new().

◆ app_translations_contexts_desc

PyStructSequence_Desc app_translations_contexts_desc
static
Initial value:
= {
"bpy.app.translations.contexts",
"This named tuple contains all predefined translation contexts",
}
#define ARRAY_SIZE(arr)
static PyStructSequence_Field app_translations_contexts_fields[ARRAY_SIZE(_contexts)]

Definition at line 408 of file bpy_app_translations.c.

Referenced by BPY_app_translations_struct().

◆ app_translations_contexts_fields

PyStructSequence_Field app_translations_contexts_fields[ARRAY_SIZE(_contexts)] = {{NULL}}
static

Definition at line 406 of file bpy_app_translations.c.

◆ app_translations_getseters

PyGetSetDef app_translations_getseters[]
static
Initial value:
= {
{"locale", (getter)app_translations_locale_get, NULL, app_translations_locale_doc, NULL},
{"locales", (getter)app_translations_locales_get, NULL, app_translations_locales_doc, NULL},
{NULL},
}
static PyObject * app_translations_locale_get(PyObject *UNUSED(self), void *UNUSED(userdata))
static PyObject * app_translations_locales_get(PyObject *UNUSED(self), void *UNUSED(userdata))

Definition at line 517 of file bpy_app_translations.c.

◆ app_translations_members

PyMemberDef app_translations_members[]
static
Initial value:
= {
{"contexts",
T_OBJECT_EX,
offsetof(BlenderAppTranslations, contexts),
READONLY,
app_translations_contexts_doc},
{"contexts_C_to_py",
T_OBJECT_EX,
offsetof(BlenderAppTranslations, contexts_C_to_py),
READONLY,
app_translations_contexts_C_to_py_doc},
{NULL},
}

Definition at line 463 of file bpy_app_translations.c.

◆ app_translations_methods

PyMethodDef app_translations_methods[]
static

Definition at line 698 of file bpy_app_translations.c.

◆ BlenderAppTranslationsContextsType

PyTypeObject BlenderAppTranslationsContextsType
static

◆ BlenderAppTranslationsType

PyTypeObject BlenderAppTranslationsType
static

Definition at line 774 of file bpy_app_translations.c.

Referenced by BPY_app_translations_struct().