Python i18n API. Many thanks to Campbell and Brecht for the reviews and suggestions!
[blender.git] / source / blender / blenfont / BLF_translation.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2011 Blender Foundation.
19  * All rights reserved.
20  *
21  *
22  * Contributor(s): Blender Foundation,
23  *                 Sergey Sharybin
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/blenfont/BLF_translation.h
29  *  \ingroup blf
30  */
31
32
33 #ifndef __BLF_TRANSLATION_H__
34 #define __BLF_TRANSLATION_H__
35
36 #define TEXT_DOMAIN_NAME "blender"
37
38 /* blf_lang.c */
39
40 /* Search the path directory to the locale files, this try all
41  * the case for Linux, Win and Mac.
42  * Also dynamically builds locales and locales' menu from "languages" text file.
43  */
44 void BLF_lang_init(void);
45
46 /* Free languages and locales_menu arrays created by BLF_lang_init. */
47 void BLF_lang_free(void);
48
49 /* Set the current locale. */
50 void BLF_lang_set(const char *);
51 /* Get the current locale (short code, e.g. es_ES). */
52 const char *BLF_lang_get(void);
53
54 /* Get locale's elements (if relevant pointer is not NULL and element actually exists, e.g. if there is no variant,
55  * *variant and *language_variant will always be NULL).
56  * Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them. 
57  */
58 void BLF_locale_explode(const char *locale, char **language, char **country, char **variant,
59                         char **language_country, char **language_variant);
60
61 /* Get EnumPropertyItem's for translations menu. */
62 struct EnumPropertyItem *BLF_RNA_lang_enum_properties(void);
63
64 /* blf_translation.c  */
65
66 #ifdef WITH_INTERNATIONAL
67 unsigned char *BLF_get_unifont(int *unifont_size);
68 void BLF_free_unifont(void);
69 #endif
70
71 const char *BLF_pgettext(const char *msgctxt, const char *msgid);
72
73 /* translation */
74 int BLF_translate_iface(void);
75 int BLF_translate_tooltips(void);
76 const char *BLF_translate_do_iface(const char *msgctxt, const char *msgid);
77 const char *BLF_translate_do_tooltip(const char *msgctxt, const char *msgid);
78
79
80 /* The "translation-marker" macro. */
81 #define N_(msgid) msgid
82 #define CTX_N_(context, msgid) msgid
83
84 /* Those macros should be used everywhere in UI code. */
85 #ifdef WITH_INTERNATIONAL
86 /*      #define _(msgid) BLF_gettext(msgid) */
87         #define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid)
88         #define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid)
89         #define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid)
90         #define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid)
91 #else
92 /*      #define _(msgid) msgid */
93         #define IFACE_(msgid) msgid
94         #define TIP_(msgid) msgid
95         #define CTX_IFACE_(context, msgid) msgid
96         #define CTX_TIP_(context, msgid)   msgid
97 #endif
98
99 /* Helper macro, when we want to define a same msgid for multiple msgctxt...
100  * Does nothing in C, but is "parsed" by our i18n py tools.
101  * XXX Currently limited to at most 16 contexts at most
102  *     (but you can call it several times with the same msgid, should you need more contexts!).
103  */
104 #define BLF_I18N_MSGID_MULTI_CTXT(msgid, ...)
105
106 /******************************************************************************
107  * All i18n contexts must be defined here.
108  * This is a nice way to be sure not to use a context twice for different
109  * things, and limit the number of existing contexts!
110  */
111
112 /* Default, void context. Just in case... */
113 #define BLF_I18NCONTEXT_DEFAULT ""
114
115 /* Default context for operator names/labels. */
116 #define BLF_I18NCONTEXT_OPERATOR_DEFAULT "Operator"
117
118 /* ID-types contexts. */
119 /* WARNING! Keep it in sync with idtypes in blenkernel/intern/idcode.c */
120 #define BLF_I18NCONTEXT_ID_ACTION               "Action"
121 #define BLF_I18NCONTEXT_ID_ARMATURE             "Armature"
122 #define BLF_I18NCONTEXT_ID_BRUSH                "Brush"
123 #define BLF_I18NCONTEXT_ID_CAMERA               "Camera"
124 #define BLF_I18NCONTEXT_ID_CURVE                "Curve"
125 #define BLF_I18NCONTEXT_ID_GPENCIL              "GPencil"
126 #define BLF_I18NCONTEXT_ID_GROUP                "Group"
127 #define BLF_I18NCONTEXT_ID_ID                   "ID"
128 #define BLF_I18NCONTEXT_ID_IMAGE                "Image"
129 /*#define BLF_I18NCONTEXT_ID_IPO                  "Ipo"*/ /* Deprecated */
130 #define BLF_I18NCONTEXT_ID_SHAPEKEY             "Key"
131 #define BLF_I18NCONTEXT_ID_LAMP                 "Lamp"
132 #define BLF_I18NCONTEXT_ID_LIBRARY              "Library"
133 #define BLF_I18NCONTEXT_ID_LATTICE              "Lattice"
134 #define BLF_I18NCONTEXT_ID_MATERIAL             "Material"
135 #define BLF_I18NCONTEXT_ID_METABALL             "Metaball"
136 #define BLF_I18NCONTEXT_ID_MESH                 "Mesh"
137 #define BLF_I18NCONTEXT_ID_NODETREE             "NodeTree"
138 #define BLF_I18NCONTEXT_ID_OBJECT               "Object"
139 #define BLF_I18NCONTEXT_ID_PARTICLESETTINGS     "ParticleSettings"
140 #define BLF_I18NCONTEXT_ID_SCENE                "Scene"
141 #define BLF_I18NCONTEXT_ID_SCREEN               "Screen"
142 #define BLF_I18NCONTEXT_ID_SEQUENCE             "Sequence"
143 #define BLF_I18NCONTEXT_ID_SPEAKER              "Speaker"
144 #define BLF_I18NCONTEXT_ID_SOUND                "Sound"
145 #define BLF_I18NCONTEXT_ID_TEXTURE              "Texture"
146 #define BLF_I18NCONTEXT_ID_TEXT                 "Text"
147 #define BLF_I18NCONTEXT_ID_VFONT                "VFont"
148 #define BLF_I18NCONTEXT_ID_WORLD                "World"
149 #define BLF_I18NCONTEXT_ID_WINDOWMANAGER        "WindowManager"
150 #define BLF_I18NCONTEXT_ID_MOVIECLIP            "MovieClip"
151 #define BLF_I18NCONTEXT_ID_MASK                 "Mask"
152
153 /* Helper for bpy.app.i18n object... */
154 typedef struct
155 {
156         const char *c_id;
157         const char *py_id;
158         const char *value;
159 } BLF_i18n_contexts_descriptor;
160
161 #define BLF_I18NCONTEXTS_ITEM(ctxt_id, py_id) {#ctxt_id, py_id, ctxt_id}
162
163 #define BLF_I18NCONTEXTS_DESC {                                                                                         \
164         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default"),                                                         \
165         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"),                                       \
166         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ACTION, "id_action"),                                                     \
167         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ARMATURE, "id_armature"),                                                 \
168         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_BRUSH, "id_brush"),                                                       \
169         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_CAMERA, "id_camera"),                                                     \
170         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_CURVE, "id_curve"),                                                       \
171         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_GPENCIL, "id_gpencil"),                                                   \
172         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_GROUP, "id_group"),                                                       \
173         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ID, "id_id"),                                                             \
174         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_IMAGE, "id_image"),                                                       \
175         /*BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_IPO, "id_ipo"),*/                                                       \
176         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SHAPEKEY, "id_shapekey"),                                                 \
177         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LAMP, "id_lamp"),                                                         \
178         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LIBRARY, "id_library"),                                                   \
179         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_LATTICE, "id_lattice"),                                                   \
180         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MATERIAL, "id_material"),                                                 \
181         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_METABALL, "id_metaball"),                                                 \
182         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MESH, "id_mesh"),                                                         \
183         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_NODETREE, "id_nodetree"),                                                 \
184         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_OBJECT, "id_object"),                                                     \
185         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_PARTICLESETTINGS, "id_particlesettings"),                                 \
186         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SCENE, "id_scene"),                                                       \
187         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SCREEN, "id_screen"),                                                     \
188         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SEQUENCE, "id_sequence"),                                                 \
189         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SPEAKER, "id_speaker"),                                                   \
190         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_SOUND, "id_sound"),                                                       \
191         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_TEXTURE, "id_texture"),                                                   \
192         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_TEXT, "id_text"),                                                         \
193         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_VFONT, "id_vfont"),                                                       \
194         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_WORLD, "id_world"),                                                       \
195         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_WINDOWMANAGER, "id_windowmanager"),                                       \
196         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MOVIECLIP, "id_movieclip"),                                               \
197         BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_MASK, "id_mask"),                                                         \
198         {NULL, NULL, NULL}                                                                                                 \
199 }
200
201 //#undef _BLF_I18NCONTEXTS_ITEM
202
203 #endif /* __BLF_TRANSLATION_H__ */