Blender V4.3
blt_translation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12#include <cstdlib>
13#include <cstring>
14
15#include "BLT_translation.hh"
16
17#include "MEM_guardedalloc.h"
18
19#include "DNA_userdef_types.h" /* For user settings. */
20
21#ifdef WITH_PYTHON
22# include "BPY_extern.hh"
23#endif
24
25#ifdef WITH_INTERNATIONAL
26# include "BLI_threads.h"
27# include "boost_locale_wrapper.h"
28#endif /* WITH_INTERNATIONAL */
29
30bool BLT_is_default_context(const char *msgctxt)
31{
32 /* We use the "short" test, a more complete one could be:
33 * return (!msgctxt || !msgctxt[0] || STREQ(msgctxt, BLT_I18NCONTEXT_DEFAULT_BPYRNA))
34 */
35 /* NOTE: trying without the void string check for now, it *should* not be necessary... */
36 return (!msgctxt || msgctxt[0] == BLT_I18NCONTEXT_DEFAULT_BPYRNA[0]);
37}
38
39const char *BLT_pgettext(const char *msgctxt, const char *msgid)
40{
41#ifdef WITH_INTERNATIONAL
42 const char *ret = msgid;
43
44 if (msgid && msgid[0]) {
45 if (BLT_is_default_context(msgctxt)) {
47 }
48 ret = bl_locale_pgettext(msgctxt, msgid);
49/* We assume if the returned string is the same (memory level) as the msgid,
50 * no translation was found, and we can try py scripts' ones!
51 */
52# ifdef WITH_PYTHON
53 if (ret == msgid) {
54 ret = BPY_app_translations_py_pgettext(msgctxt, msgid);
55 }
56# endif
57 }
58
59 return ret;
60#else
61 (void)msgctxt;
62 return msgid;
63#endif
64}
65
67{
68#ifdef WITH_INTERNATIONAL
69 return BLI_thread_is_main();
70#else
71 return false;
72#endif
73}
74
76{
77#ifdef WITH_INTERNATIONAL
78 return BLT_translate() && (U.transopts & USER_TR_IFACE);
79#else
80 return false;
81#endif
82}
83
85{
86#ifdef WITH_INTERNATIONAL
87 return BLT_translate() && (U.transopts & USER_TR_TOOLTIPS);
88#else
89 return false;
90#endif
91}
92
94{
95#ifdef WITH_INTERNATIONAL
96 return BLT_translate() && (U.transopts & USER_TR_REPORTS);
97#else
98 return false;
99#endif
100}
101
103{
104#ifdef WITH_INTERNATIONAL
105 return BLT_translate() && (U.transopts & USER_TR_NEWDATANAME);
106#else
107 return false;
108#endif
109}
110
111const char *BLT_translate_do(const char *msgctxt, const char *msgid)
112{
113#ifdef WITH_INTERNATIONAL
114 if (BLT_translate()) {
115 return BLT_pgettext(msgctxt, msgid);
116 }
117
118 return msgid;
119
120#else
121 (void)msgctxt;
122 return msgid;
123#endif
124}
125
126const char *BLT_translate_do_iface(const char *msgctxt, const char *msgid)
127{
128#ifdef WITH_INTERNATIONAL
129 if (BLT_translate_iface()) {
130 return BLT_pgettext(msgctxt, msgid);
131 }
132
133 return msgid;
134
135#else
136 (void)msgctxt;
137 return msgid;
138#endif
139}
140
141const char *BLT_translate_do_tooltip(const char *msgctxt, const char *msgid)
142{
143#ifdef WITH_INTERNATIONAL
145 return BLT_pgettext(msgctxt, msgid);
146 }
147
148 return msgid;
149
150#else
151 (void)msgctxt;
152 return msgid;
153#endif
154}
155
156const char *BLT_translate_do_report(const char *msgctxt, const char *msgid)
157{
158#ifdef WITH_INTERNATIONAL
159 if (BLT_translate_reports()) {
160 return BLT_pgettext(msgctxt, msgid);
161 }
162
163 return msgid;
164
165#else
166 (void)msgctxt;
167 return msgid;
168#endif
169}
170
171const char *BLT_translate_do_new_dataname(const char *msgctxt, const char *msgid)
172{
173#ifdef WITH_INTERNATIONAL
175 return BLT_pgettext(msgctxt, msgid);
176 }
177
178 return msgid;
179
180#else
181 (void)msgctxt;
182 return msgid;
183#endif
184}
int BLI_thread_is_main(void)
Definition threads.cc:179
#define BLT_I18NCONTEXT_DEFAULT
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
@ USER_TR_REPORTS
@ USER_TR_NEWDATANAME
@ USER_TR_TOOLTIPS
@ USER_TR_IFACE
Read Guarded memory(de)allocation.
const char * BLT_translate_do(const char *msgctxt, const char *msgid)
bool BLT_translate_iface()
bool BLT_translate_new_dataname()
const char * BLT_pgettext(const char *msgctxt, const char *msgid)
bool BLT_translate_reports()
const char * BLT_translate_do_tooltip(const char *msgctxt, const char *msgid)
bool BLT_is_default_context(const char *msgctxt)
bool BLT_translate()
bool BLT_translate_tooltips()
const char * BLT_translate_do_iface(const char *msgctxt, const char *msgid)
const char * BLT_translate_do_new_dataname(const char *msgctxt, const char *msgid)
const char * BLT_translate_do_report(const char *msgctxt, const char *msgid)
const char * bl_locale_pgettext(const char *msgctxt, const char *msgid)
unsigned int U
Definition btGjkEpa3.h:78
return ret