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