Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/blentranslation
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/blentranslation')
-rw-r--r--source/blender/blentranslation/BLT_lang.h9
-rw-r--r--source/blender/blentranslation/BLT_translation.h194
-rw-r--r--source/blender/blentranslation/CMakeLists.txt50
-rw-r--r--source/blender/blentranslation/intern/blt_lang.c495
-rw-r--r--source/blender/blentranslation/intern/blt_translation.c134
-rw-r--r--source/blender/blentranslation/msgfmt/CMakeLists.txt8
-rw-r--r--source/blender/blentranslation/msgfmt/msgfmt.c689
7 files changed, 795 insertions, 784 deletions
diff --git a/source/blender/blentranslation/BLT_lang.h b/source/blender/blentranslation/BLT_lang.h
index 3000c2f66a6..544f2701258 100644
--- a/source/blender/blentranslation/BLT_lang.h
+++ b/source/blender/blentranslation/BLT_lang.h
@@ -47,9 +47,12 @@ const char *BLT_lang_get(void);
* Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them.
* NOTE: Always available, even in non-WITH_INTERNATIONAL builds.
*/
-void BLT_lang_locale_explode(
- const char *locale, char **language, char **country, char **variant,
- char **language_country, char **language_variant);
+void BLT_lang_locale_explode(const char *locale,
+ char **language,
+ char **country,
+ char **variant,
+ char **language_country,
+ char **language_variant);
/* Get EnumPropertyItem's for translations menu. */
struct EnumPropertyItem *BLT_lang_RNA_enum_properties(void);
diff --git a/source/blender/blentranslation/BLT_translation.h b/source/blender/blentranslation/BLT_translation.h
index b1375fd74a8..5fdae83951c 100644
--- a/source/blender/blentranslation/BLT_translation.h
+++ b/source/blender/blentranslation/BLT_translation.h
@@ -21,11 +21,10 @@
* \ingroup blt
*/
-
#ifndef __BLT_TRANSLATION_H__
#define __BLT_TRANSLATION_H__
-#include "BLI_utildefines.h" /* for bool type */
+#include "BLI_utildefines.h" /* for bool type */
#define TEXT_DOMAIN_NAME "blender"
@@ -64,11 +63,11 @@ bool BLT_lang_is_ime_supported(void);
#else
/*# define _(msgid) msgid */
# define IFACE_(msgid) msgid
-# define TIP_(msgid) msgid
-# define DATA_(msgid) msgid
+# define TIP_(msgid) msgid
+# define DATA_(msgid) msgid
# define CTX_IFACE_(context, msgid) msgid
-# define CTX_TIP_(context, msgid) msgid
-# define CTX_DATA_(context, msgid) msgid
+# define CTX_TIP_(context, msgid) msgid
+# define CTX_DATA_(context, msgid) msgid
#endif
/* Helper macro, when we want to define a same msgid for multiple msgctxt...
@@ -108,100 +107,107 @@ bool BLT_lang_is_ime_supported(void);
/* ID-types contexts. */
/* WARNING! Keep it in sync with idtypes in blenkernel/intern/idcode.c */
-#define BLT_I18NCONTEXT_ID_ACTION "Action"
-#define BLT_I18NCONTEXT_ID_ARMATURE "Armature"
-#define BLT_I18NCONTEXT_ID_BRUSH "Brush"
-#define BLT_I18NCONTEXT_ID_CAMERA "Camera"
-#define BLT_I18NCONTEXT_ID_CACHEFILE "CacheFile"
-#define BLT_I18NCONTEXT_ID_COLLECTION "Collection"
-#define BLT_I18NCONTEXT_ID_CURVE "Curve"
-#define BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE "FreestyleLineStyle"
-#define BLT_I18NCONTEXT_ID_GPENCIL "GPencil"
-#define BLT_I18NCONTEXT_ID_ID "ID"
-#define BLT_I18NCONTEXT_ID_IMAGE "Image"
+#define BLT_I18NCONTEXT_ID_ACTION "Action"
+#define BLT_I18NCONTEXT_ID_ARMATURE "Armature"
+#define BLT_I18NCONTEXT_ID_BRUSH "Brush"
+#define BLT_I18NCONTEXT_ID_CAMERA "Camera"
+#define BLT_I18NCONTEXT_ID_CACHEFILE "CacheFile"
+#define BLT_I18NCONTEXT_ID_COLLECTION "Collection"
+#define BLT_I18NCONTEXT_ID_CURVE "Curve"
+#define BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE "FreestyleLineStyle"
+#define BLT_I18NCONTEXT_ID_GPENCIL "GPencil"
+#define BLT_I18NCONTEXT_ID_ID "ID"
+#define BLT_I18NCONTEXT_ID_IMAGE "Image"
/*#define BLT_I18NCONTEXT_ID_IPO "Ipo"*/ /* Deprecated */
-#define BLT_I18NCONTEXT_ID_SHAPEKEY "Key"
-#define BLT_I18NCONTEXT_ID_LIGHT "Light"
-#define BLT_I18NCONTEXT_ID_LIBRARY "Library"
-#define BLT_I18NCONTEXT_ID_LATTICE "Lattice"
-#define BLT_I18NCONTEXT_ID_MATERIAL "Material"
-#define BLT_I18NCONTEXT_ID_METABALL "Metaball"
-#define BLT_I18NCONTEXT_ID_MESH "Mesh"
-#define BLT_I18NCONTEXT_ID_NODETREE "NodeTree"
-#define BLT_I18NCONTEXT_ID_OBJECT "Object"
-#define BLT_I18NCONTEXT_ID_PAINTCURVE "PaintCurve"
-#define BLT_I18NCONTEXT_ID_PALETTE "Palette"
-#define BLT_I18NCONTEXT_ID_PARTICLESETTINGS "ParticleSettings"
-#define BLT_I18NCONTEXT_ID_LIGHTPROBE "LightProbe"
-#define BLT_I18NCONTEXT_ID_SCENE "Scene"
-#define BLT_I18NCONTEXT_ID_SCREEN "Screen"
-#define BLT_I18NCONTEXT_ID_SEQUENCE "Sequence"
-#define BLT_I18NCONTEXT_ID_SPEAKER "Speaker"
-#define BLT_I18NCONTEXT_ID_SOUND "Sound"
-#define BLT_I18NCONTEXT_ID_TEXTURE "Texture"
-#define BLT_I18NCONTEXT_ID_TEXT "Text"
-#define BLT_I18NCONTEXT_ID_VFONT "VFont"
-#define BLT_I18NCONTEXT_ID_WORLD "World"
-#define BLT_I18NCONTEXT_ID_WORKSPACE "WorkSpace"
-#define BLT_I18NCONTEXT_ID_WINDOWMANAGER "WindowManager"
-#define BLT_I18NCONTEXT_ID_MOVIECLIP "MovieClip"
-#define BLT_I18NCONTEXT_ID_MASK "Mask"
+#define BLT_I18NCONTEXT_ID_SHAPEKEY "Key"
+#define BLT_I18NCONTEXT_ID_LIGHT "Light"
+#define BLT_I18NCONTEXT_ID_LIBRARY "Library"
+#define BLT_I18NCONTEXT_ID_LATTICE "Lattice"
+#define BLT_I18NCONTEXT_ID_MATERIAL "Material"
+#define BLT_I18NCONTEXT_ID_METABALL "Metaball"
+#define BLT_I18NCONTEXT_ID_MESH "Mesh"
+#define BLT_I18NCONTEXT_ID_NODETREE "NodeTree"
+#define BLT_I18NCONTEXT_ID_OBJECT "Object"
+#define BLT_I18NCONTEXT_ID_PAINTCURVE "PaintCurve"
+#define BLT_I18NCONTEXT_ID_PALETTE "Palette"
+#define BLT_I18NCONTEXT_ID_PARTICLESETTINGS "ParticleSettings"
+#define BLT_I18NCONTEXT_ID_LIGHTPROBE "LightProbe"
+#define BLT_I18NCONTEXT_ID_SCENE "Scene"
+#define BLT_I18NCONTEXT_ID_SCREEN "Screen"
+#define BLT_I18NCONTEXT_ID_SEQUENCE "Sequence"
+#define BLT_I18NCONTEXT_ID_SPEAKER "Speaker"
+#define BLT_I18NCONTEXT_ID_SOUND "Sound"
+#define BLT_I18NCONTEXT_ID_TEXTURE "Texture"
+#define BLT_I18NCONTEXT_ID_TEXT "Text"
+#define BLT_I18NCONTEXT_ID_VFONT "VFont"
+#define BLT_I18NCONTEXT_ID_WORLD "World"
+#define BLT_I18NCONTEXT_ID_WORKSPACE "WorkSpace"
+#define BLT_I18NCONTEXT_ID_WINDOWMANAGER "WindowManager"
+#define BLT_I18NCONTEXT_ID_MOVIECLIP "MovieClip"
+#define BLT_I18NCONTEXT_ID_MASK "Mask"
/* Helper for bpy.app.i18n object... */
typedef struct {
- const char *c_id;
- const char *py_id;
- const char *value;
+ const char *c_id;
+ const char *py_id;
+ const char *value;
} BLT_i18n_contexts_descriptor;
-#define BLT_I18NCONTEXTS_ITEM(ctxt_id, py_id) {#ctxt_id, py_id, ctxt_id}
-
-#define BLT_I18NCONTEXTS_DESC { \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_DEFAULT, "default_real"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_DEFAULT_BPYRNA, "default"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_UI_EVENTS, "ui_events_keymaps"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_PLURAL, "plural"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ACTION, "id_action"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ARMATURE, "id_armature"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_BRUSH, "id_brush"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CAMERA, "id_camera"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CACHEFILE, "id_cachefile"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_COLLECTION, "id_collection"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CURVE, "id_curve"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, "id_fs_linestyle"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_GPENCIL, "id_gpencil"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ID, "id_id"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_IMAGE, "id_image"), \
- /*BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_IPO, "id_ipo"),*/ \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SHAPEKEY, "id_shapekey"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIGHT, "id_light"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIBRARY, "id_library"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LATTICE, "id_lattice"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MASK, "id_mask"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MATERIAL, "id_material"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_METABALL, "id_metaball"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MESH, "id_mesh"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MOVIECLIP, "id_movieclip"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_NODETREE, "id_nodetree"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_OBJECT, "id_object"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PAINTCURVE, "id_paintcurve"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PALETTE, "id_palette"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PARTICLESETTINGS, "id_particlesettings"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIGHTPROBE, "id_lightprobe"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SCENE, "id_scene"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SCREEN, "id_screen"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SEQUENCE, "id_sequence"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SPEAKER, "id_speaker"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SOUND, "id_sound"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_TEXTURE, "id_texture"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_TEXT, "id_text"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_VFONT, "id_vfont"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WORLD, "id_world"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WORKSPACE, "id_workspace"), \
- BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "id_windowmanager"), \
- {NULL, NULL, NULL} \
-}
+#define BLT_I18NCONTEXTS_ITEM(ctxt_id, py_id) \
+ { \
+# ctxt_id, py_id, ctxt_id \
+ }
+
+#define BLT_I18NCONTEXTS_DESC \
+ { \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_DEFAULT, "default_real"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_DEFAULT_BPYRNA, "default"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_UI_EVENTS, "ui_events_keymaps"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_PLURAL, "plural"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ACTION, "id_action"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ARMATURE, "id_armature"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_BRUSH, "id_brush"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CAMERA, "id_camera"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CACHEFILE, "id_cachefile"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_COLLECTION, "id_collection"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_CURVE, "id_curve"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, "id_fs_linestyle"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_GPENCIL, "id_gpencil"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ID, "id_id"), \
+ BLT_I18NCONTEXTS_ITEM( \
+ BLT_I18NCONTEXT_ID_IMAGE, \
+ "id_image"), /*BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_IPO, "id_ipo"),*/ \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SHAPEKEY, "id_shapekey"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIGHT, "id_light"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIBRARY, "id_library"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LATTICE, "id_lattice"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MASK, "id_mask"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MATERIAL, "id_material"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_METABALL, "id_metaball"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MESH, "id_mesh"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_MOVIECLIP, "id_movieclip"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_NODETREE, "id_nodetree"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_OBJECT, "id_object"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PAINTCURVE, "id_paintcurve"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PALETTE, "id_palette"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PARTICLESETTINGS, "id_particlesettings"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIGHTPROBE, "id_lightprobe"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SCENE, "id_scene"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SCREEN, "id_screen"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SEQUENCE, "id_sequence"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SPEAKER, "id_speaker"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SOUND, "id_sound"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_TEXTURE, "id_texture"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_TEXT, "id_text"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_VFONT, "id_vfont"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WORLD, "id_world"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WORKSPACE, "id_workspace"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "id_windowmanager"), \
+ { \
+ NULL, NULL, NULL \
+ } \
+ }
#ifdef __cplusplus
};
diff --git a/source/blender/blentranslation/CMakeLists.txt b/source/blender/blentranslation/CMakeLists.txt
index 5bb35d79373..34952911dce 100644
--- a/source/blender/blentranslation/CMakeLists.txt
+++ b/source/blender/blentranslation/CMakeLists.txt
@@ -19,53 +19,53 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- .
- ../blenkernel
- ../blenlib
- ../makesdna
- ../makesrna
- ../../../intern/guardedalloc
- ../../../intern/locale
+ .
+ ../blenkernel
+ ../blenlib
+ ../makesdna
+ ../makesrna
+ ../../../intern/guardedalloc
+ ../../../intern/locale
)
set(INC_SYS
)
set(SRC
- intern/blt_lang.c
- intern/blt_translation.c
+ intern/blt_lang.c
+ intern/blt_translation.c
- BLT_lang.h
- BLT_translation.h
+ BLT_lang.h
+ BLT_translation.h
)
set(LIB
- bf_blenkernel
- bf_blenlib
+ bf_blenkernel
+ bf_blenlib
)
if(WITH_INTERNATIONAL)
- add_definitions(-DWITH_INTERNATIONAL)
- list(APPEND LIB
- bf_intern_locale
- )
+ add_definitions(-DWITH_INTERNATIONAL)
+ list(APPEND LIB
+ bf_intern_locale
+ )
endif()
if(WITH_PYTHON)
- add_definitions(-DWITH_PYTHON)
- list(APPEND INC
- ../python
- )
+ add_definitions(-DWITH_PYTHON)
+ list(APPEND INC
+ ../python
+ )
endif()
if(WIN32)
- if(WITH_INPUT_IME)
- add_definitions(-DWITH_INPUT_IME)
- endif()
+ if(WITH_INPUT_IME)
+ add_definitions(-DWITH_INPUT_IME)
+ endif()
endif()
blender_add_lib(bf_blentranslation "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
if(WITH_INTERNATIONAL)
- add_subdirectory(msgfmt)
+ add_subdirectory(msgfmt)
endif()
diff --git a/source/blender/blentranslation/intern/blt_lang.c b/source/blender/blentranslation/intern/blt_lang.c
index b7f6fcd0b66..e8955235198 100644
--- a/source/blender/blentranslation/intern/blt_lang.c
+++ b/source/blender/blentranslation/intern/blt_lang.c
@@ -34,7 +34,7 @@
#include "RNA_types.h"
#include "BLT_translation.h"
-#include "BLT_lang.h" /* own include */
+#include "BLT_lang.h" /* own include */
#include "BLI_path_util.h"
#include "BLI_string.h"
@@ -52,10 +52,10 @@ static void blt_lang_check_ime_supported(void);
#ifdef WITH_INTERNATIONAL
-#include "BLI_fileops.h"
-#include "BLI_linklist.h"
+# include "BLI_fileops.h"
+# include "BLI_linklist.h"
-#include "boost_locale_wrapper.h"
+# include "boost_locale_wrapper.h"
/* Locale options. */
static const char **locales = NULL;
@@ -65,175 +65,176 @@ static int num_locales_menu = 0;
static void free_locales(void)
{
- if (locales) {
- int idx = num_locales_menu - 1; /* Last item does not need to be freed! */
- while (idx--) {
- MEM_freeN((void *)locales_menu[idx].identifier);
- MEM_freeN((void *)locales_menu[idx].name);
- MEM_freeN((void *)locales_menu[idx].description); /* Also frees locales's relevant value! */
- }
-
- MEM_freeN((void *)locales);
- locales = NULL;
- }
- if (locales_menu) {
- MEM_freeN(locales_menu);
- locales_menu = NULL;
- }
- num_locales = num_locales_menu = 0;
+ if (locales) {
+ int idx = num_locales_menu - 1; /* Last item does not need to be freed! */
+ while (idx--) {
+ MEM_freeN((void *)locales_menu[idx].identifier);
+ MEM_freeN((void *)locales_menu[idx].name);
+ MEM_freeN((void *)locales_menu[idx].description); /* Also frees locales's relevant value! */
+ }
+
+ MEM_freeN((void *)locales);
+ locales = NULL;
+ }
+ if (locales_menu) {
+ MEM_freeN(locales_menu);
+ locales_menu = NULL;
+ }
+ num_locales = num_locales_menu = 0;
}
static void fill_locales(void)
{
- const char * const languages_path = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale");
- char languages[FILE_MAX];
- LinkNode *lines = NULL, *line;
- char *str;
- int idx = 0;
-
- free_locales();
-
- BLI_join_dirfile(languages, FILE_MAX, languages_path, "languages");
- line = lines = BLI_file_read_as_lines(languages);
-
- /* This whole "parsing" code is a bit weak, in that it expects strictly formatted input file...
- * Should not be a problem, though, as this file is script-generated! */
-
- /* First loop to find highest locale ID */
- while (line) {
- int t;
- str = (char *)line->link;
- if (str[0] == '#' || str[0] == '\0') {
- line = line->next;
- continue; /* Comment or void... */
- }
- t = atoi(str);
- if (t >= num_locales)
- num_locales = t + 1;
- num_locales_menu++;
- line = line->next;
- }
- num_locales_menu++; /* The "closing" void item... */
-
- /* And now, build locales and locale_menu! */
- locales_menu = MEM_callocN(num_locales_menu * sizeof(EnumPropertyItem), __func__);
- line = lines;
- /* Do not allocate locales with zero-sized mem, as LOCALE macro uses NULL locales as invalid marker! */
- if (num_locales > 0) {
- locales = MEM_callocN(num_locales * sizeof(char *), __func__);
- while (line) {
- int id;
- char *loc, *sep1, *sep2, *sep3;
-
- str = (char *)line->link;
- if (str[0] == '#' || str[0] == '\0') {
- line = line->next;
- continue;
- }
-
- id = atoi(str);
- sep1 = strchr(str, ':');
- if (sep1) {
- sep1++;
- sep2 = strchr(sep1, ':');
- if (sep2) {
- locales_menu[idx].value = id;
- locales_menu[idx].icon = 0;
- locales_menu[idx].name = BLI_strdupn(sep1, sep2 - sep1);
-
- sep2++;
- sep3 = strchr(sep2, ':');
-
- if (sep3) {
- locales_menu[idx].identifier = loc = BLI_strdupn(sep2, sep3 - sep2);
- }
- else {
- locales_menu[idx].identifier = loc = BLI_strdup(sep2);
- }
-
- if (id == 0) {
- /* The DEFAULT/Automatic item... */
- if (BLI_strnlen(loc, 2)) {
- locales[id] = "";
- /* Keep this tip in sync with the one in rna_userdef (rna_enum_language_default_items). */
- locales_menu[idx].description = BLI_strdup("Automatically choose system's defined language "
- "if available, or fall-back to English");
- }
- /* Menu "label", not to be stored in locales! */
- else {
- locales_menu[idx].description = BLI_strdup("");
- }
- }
- else {
- locales[id] = locales_menu[idx].description = BLI_strdup(loc);
- }
- idx++;
- }
- }
-
- line = line->next;
- }
- }
-
- /* Add closing item to menu! */
- locales_menu[idx].identifier = NULL;
- locales_menu[idx].value = locales_menu[idx].icon = 0;
- locales_menu[idx].name = locales_menu[idx].description = "";
-
- BLI_file_free_lines(lines);
+ const char *const languages_path = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale");
+ char languages[FILE_MAX];
+ LinkNode *lines = NULL, *line;
+ char *str;
+ int idx = 0;
+
+ free_locales();
+
+ BLI_join_dirfile(languages, FILE_MAX, languages_path, "languages");
+ line = lines = BLI_file_read_as_lines(languages);
+
+ /* This whole "parsing" code is a bit weak, in that it expects strictly formatted input file...
+ * Should not be a problem, though, as this file is script-generated! */
+
+ /* First loop to find highest locale ID */
+ while (line) {
+ int t;
+ str = (char *)line->link;
+ if (str[0] == '#' || str[0] == '\0') {
+ line = line->next;
+ continue; /* Comment or void... */
+ }
+ t = atoi(str);
+ if (t >= num_locales)
+ num_locales = t + 1;
+ num_locales_menu++;
+ line = line->next;
+ }
+ num_locales_menu++; /* The "closing" void item... */
+
+ /* And now, build locales and locale_menu! */
+ locales_menu = MEM_callocN(num_locales_menu * sizeof(EnumPropertyItem), __func__);
+ line = lines;
+ /* Do not allocate locales with zero-sized mem, as LOCALE macro uses NULL locales as invalid marker! */
+ if (num_locales > 0) {
+ locales = MEM_callocN(num_locales * sizeof(char *), __func__);
+ while (line) {
+ int id;
+ char *loc, *sep1, *sep2, *sep3;
+
+ str = (char *)line->link;
+ if (str[0] == '#' || str[0] == '\0') {
+ line = line->next;
+ continue;
+ }
+
+ id = atoi(str);
+ sep1 = strchr(str, ':');
+ if (sep1) {
+ sep1++;
+ sep2 = strchr(sep1, ':');
+ if (sep2) {
+ locales_menu[idx].value = id;
+ locales_menu[idx].icon = 0;
+ locales_menu[idx].name = BLI_strdupn(sep1, sep2 - sep1);
+
+ sep2++;
+ sep3 = strchr(sep2, ':');
+
+ if (sep3) {
+ locales_menu[idx].identifier = loc = BLI_strdupn(sep2, sep3 - sep2);
+ }
+ else {
+ locales_menu[idx].identifier = loc = BLI_strdup(sep2);
+ }
+
+ if (id == 0) {
+ /* The DEFAULT/Automatic item... */
+ if (BLI_strnlen(loc, 2)) {
+ locales[id] = "";
+ /* Keep this tip in sync with the one in rna_userdef (rna_enum_language_default_items). */
+ locales_menu[idx].description = BLI_strdup(
+ "Automatically choose system's defined language "
+ "if available, or fall-back to English");
+ }
+ /* Menu "label", not to be stored in locales! */
+ else {
+ locales_menu[idx].description = BLI_strdup("");
+ }
+ }
+ else {
+ locales[id] = locales_menu[idx].description = BLI_strdup(loc);
+ }
+ idx++;
+ }
+ }
+
+ line = line->next;
+ }
+ }
+
+ /* Add closing item to menu! */
+ locales_menu[idx].identifier = NULL;
+ locales_menu[idx].value = locales_menu[idx].icon = 0;
+ locales_menu[idx].name = locales_menu[idx].description = "";
+
+ BLI_file_free_lines(lines);
}
-#endif /* WITH_INTERNATIONAL */
+#endif /* WITH_INTERNATIONAL */
EnumPropertyItem *BLT_lang_RNA_enum_properties(void)
{
#ifdef WITH_INTERNATIONAL
- return locales_menu;
+ return locales_menu;
#else
- return NULL;
+ return NULL;
#endif
}
void BLT_lang_init(void)
{
#ifdef WITH_INTERNATIONAL
- const char * const messagepath = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale");
+ const char *const messagepath = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale");
#endif
- /* Make sure LANG is correct and wouldn't cause std::rumtime_error. */
+ /* Make sure LANG is correct and wouldn't cause std::rumtime_error. */
#ifndef _WIN32
- /* TODO(sergey): This code only ensures LANG is set properly, so later when
- * Cycles will try to use file system API from boost there'll be no runtime
- * exception generated by std::locale() which _requires_ having proper LANG
- * set in the environment.
- *
- * Ideally we also need to ensure LC_ALL, LC_MESSAGES and others are also
- * set to a proper value, but currently it's not a huge deal and doesn't
- * cause any headache.
- *
- * Would also be good to find nicer way to check if LANG is correct.
- */
- const char *lang = BLI_getenv("LANG");
- if (lang != NULL) {
- char *old_locale = setlocale(LC_ALL, NULL);
- /* Make a copy so subsequenct setlocale() doesn't interfere. */
- old_locale = BLI_strdup(old_locale);
- if (setlocale(LC_ALL, lang) == NULL) {
- setenv("LANG", "C", 1);
- printf("Warning: Falling back to the standard locale (\"C\")\n");
- }
- setlocale(LC_ALL, old_locale);
- MEM_freeN(old_locale);
- }
+ /* TODO(sergey): This code only ensures LANG is set properly, so later when
+ * Cycles will try to use file system API from boost there'll be no runtime
+ * exception generated by std::locale() which _requires_ having proper LANG
+ * set in the environment.
+ *
+ * Ideally we also need to ensure LC_ALL, LC_MESSAGES and others are also
+ * set to a proper value, but currently it's not a huge deal and doesn't
+ * cause any headache.
+ *
+ * Would also be good to find nicer way to check if LANG is correct.
+ */
+ const char *lang = BLI_getenv("LANG");
+ if (lang != NULL) {
+ char *old_locale = setlocale(LC_ALL, NULL);
+ /* Make a copy so subsequenct setlocale() doesn't interfere. */
+ old_locale = BLI_strdup(old_locale);
+ if (setlocale(LC_ALL, lang) == NULL) {
+ setenv("LANG", "C", 1);
+ printf("Warning: Falling back to the standard locale (\"C\")\n");
+ }
+ setlocale(LC_ALL, old_locale);
+ MEM_freeN(old_locale);
+ }
#endif
#ifdef WITH_INTERNATIONAL
- if (messagepath) {
- bl_locale_init(messagepath, TEXT_DOMAIN_NAME);
- fill_locales();
- }
- else {
- printf("%s: 'locale' data path for translations not found, continuing\n", __func__);
- }
+ if (messagepath) {
+ bl_locale_init(messagepath, TEXT_DOMAIN_NAME);
+ fill_locales();
+ }
+ else {
+ printf("%s: 'locale' data path for translations not found, continuing\n", __func__);
+ }
#else
#endif
}
@@ -241,7 +242,7 @@ void BLT_lang_init(void)
void BLT_lang_free(void)
{
#ifdef WITH_INTERNATIONAL
- free_locales();
+ free_locales();
#else
#endif
}
@@ -254,52 +255,52 @@ void BLT_lang_free(void)
void BLT_lang_set(const char *str)
{
#ifdef WITH_INTERNATIONAL
- int ulang = ULANGUAGE;
- const char *short_locale = str ? str : LOCALE(ulang);
- const char *short_locale_utf8 = NULL;
-
- if ((U.transopts & USER_DOTRANSLATE) == 0)
- return;
-
- /* We want to avoid locales like '.UTF-8'! */
- if (short_locale[0]) {
- /* Hurrey! encoding needs to be placed *before* variant! */
- char *variant = strchr(short_locale, '@');
- if (variant) {
- char *locale = BLI_strdupn(short_locale, variant - short_locale);
- short_locale_utf8 = BLI_sprintfN("%s.UTF-8%s", locale, variant);
- MEM_freeN(locale);
- }
- else {
- short_locale_utf8 = BLI_sprintfN("%s.UTF-8", short_locale);
- }
- bl_locale_set(short_locale_utf8);
- MEM_freeN((void *)short_locale_utf8);
- }
- else {
- bl_locale_set(short_locale);
- }
+ int ulang = ULANGUAGE;
+ const char *short_locale = str ? str : LOCALE(ulang);
+ const char *short_locale_utf8 = NULL;
+
+ if ((U.transopts & USER_DOTRANSLATE) == 0)
+ return;
+
+ /* We want to avoid locales like '.UTF-8'! */
+ if (short_locale[0]) {
+ /* Hurrey! encoding needs to be placed *before* variant! */
+ char *variant = strchr(short_locale, '@');
+ if (variant) {
+ char *locale = BLI_strdupn(short_locale, variant - short_locale);
+ short_locale_utf8 = BLI_sprintfN("%s.UTF-8%s", locale, variant);
+ MEM_freeN(locale);
+ }
+ else {
+ short_locale_utf8 = BLI_sprintfN("%s.UTF-8", short_locale);
+ }
+ bl_locale_set(short_locale_utf8);
+ MEM_freeN((void *)short_locale_utf8);
+ }
+ else {
+ bl_locale_set(short_locale);
+ }
#else
- (void)str;
+ (void)str;
#endif
- blt_lang_check_ime_supported();
+ blt_lang_check_ime_supported();
}
/* Get the current locale (short code, e.g. es_ES). */
const char *BLT_lang_get(void)
{
#ifdef WITH_INTERNATIONAL
- if (BLT_translate()) {
- const char *locale = LOCALE(ULANGUAGE);
- if (locale[0] == '\0') {
- /* Default locale, we have to find which one we are actually using! */
- locale = bl_locale_get();
- }
- return locale;
- }
- return "en_US"; /* Kind of default locale in Blender when no translation enabled. */
+ if (BLT_translate()) {
+ const char *locale = LOCALE(ULANGUAGE);
+ if (locale[0] == '\0') {
+ /* Default locale, we have to find which one we are actually using! */
+ locale = bl_locale_get();
+ }
+ return locale;
+ }
+ return "en_US"; /* Kind of default locale in Blender when no translation enabled. */
#else
- return "";
+ return "";
#endif
}
@@ -311,52 +312,55 @@ const char *BLT_lang_get(void)
* Non-null elements are always MEM_mallocN'ed, it's the caller's responsibility to free them.
* NOTE: Keep that one always available, you never know, may become useful even in no-WITH_INTERNATIONAL context...
*/
-void BLT_lang_locale_explode(
- const char *locale, char **language, char **country, char **variant,
- char **language_country, char **language_variant)
+void BLT_lang_locale_explode(const char *locale,
+ char **language,
+ char **country,
+ char **variant,
+ char **language_country,
+ char **language_variant)
{
- char *m1, *m2, *_t = NULL;
-
- m1 = strchr(locale, '_');
- m2 = strchr(locale, '@');
-
- if (language || language_variant) {
- if (m1 || m2) {
- _t = m1 ? BLI_strdupn(locale, m1 - locale) : BLI_strdupn(locale, m2 - locale);
- if (language)
- *language = _t;
- }
- else if (language) {
- *language = BLI_strdup(locale);
- }
- }
- if (country) {
- if (m1)
- *country = m2 ? BLI_strdupn(m1 + 1, m2 - (m1 + 1)) : BLI_strdup(m1 + 1);
- else
- *country = NULL;
- }
- if (variant) {
- if (m2)
- *variant = BLI_strdup(m2 + 1);
- else
- *variant = NULL;
- }
- if (language_country) {
- if (m1)
- *language_country = m2 ? BLI_strdupn(locale, m2 - locale) : BLI_strdup(locale);
- else
- *language_country = NULL;
- }
- if (language_variant) {
- if (m2)
- *language_variant = m1 ? BLI_strdupcat(_t, m2) : BLI_strdup(locale);
- else
- *language_variant = NULL;
- }
- if (_t && !language) {
- MEM_freeN(_t);
- }
+ char *m1, *m2, *_t = NULL;
+
+ m1 = strchr(locale, '_');
+ m2 = strchr(locale, '@');
+
+ if (language || language_variant) {
+ if (m1 || m2) {
+ _t = m1 ? BLI_strdupn(locale, m1 - locale) : BLI_strdupn(locale, m2 - locale);
+ if (language)
+ *language = _t;
+ }
+ else if (language) {
+ *language = BLI_strdup(locale);
+ }
+ }
+ if (country) {
+ if (m1)
+ *country = m2 ? BLI_strdupn(m1 + 1, m2 - (m1 + 1)) : BLI_strdup(m1 + 1);
+ else
+ *country = NULL;
+ }
+ if (variant) {
+ if (m2)
+ *variant = BLI_strdup(m2 + 1);
+ else
+ *variant = NULL;
+ }
+ if (language_country) {
+ if (m1)
+ *language_country = m2 ? BLI_strdupn(locale, m2 - locale) : BLI_strdup(locale);
+ else
+ *language_country = NULL;
+ }
+ if (language_variant) {
+ if (m2)
+ *language_variant = m1 ? BLI_strdupcat(_t, m2) : BLI_strdup(locale);
+ else
+ *language_variant = NULL;
+ }
+ if (_t && !language) {
+ MEM_freeN(_t);
+ }
}
/* Test if the translation context allows IME input - used to
@@ -365,25 +369,24 @@ void BLT_lang_locale_explode(
static void blt_lang_check_ime_supported(void)
{
#ifdef WITH_INPUT_IME
- const char *uilng = BLT_lang_get();
- if (U.transopts & USER_DOTRANSLATE) {
- ime_is_lang_supported = STREQ(uilng, "zh_CN") ||
- STREQ(uilng, "zh_TW") ||
- STREQ(uilng, "ja_JP");
- }
- else {
- ime_is_lang_supported = false;
- }
+ const char *uilng = BLT_lang_get();
+ if (U.transopts & USER_DOTRANSLATE) {
+ ime_is_lang_supported = STREQ(uilng, "zh_CN") || STREQ(uilng, "zh_TW") ||
+ STREQ(uilng, "ja_JP");
+ }
+ else {
+ ime_is_lang_supported = false;
+ }
#else
- ime_is_lang_supported = false;
+ ime_is_lang_supported = false;
#endif
}
bool BLT_lang_is_ime_supported(void)
{
#ifdef WITH_INPUT_IME
- return ime_is_lang_supported;
+ return ime_is_lang_supported;
#else
- return false;
+ return false;
#endif
}
diff --git a/source/blender/blentranslation/intern/blt_translation.c b/source/blender/blentranslation/intern/blt_translation.c
index 0245a1a0c35..a4bac6bc01f 100644
--- a/source/blender/blentranslation/intern/blt_translation.c
+++ b/source/blender/blentranslation/intern/blt_translation.c
@@ -34,142 +34,142 @@
#include "DNA_userdef_types.h" /* For user settings. */
#ifdef WITH_PYTHON
-#include "BPY_extern.h"
+# include "BPY_extern.h"
#endif
#ifdef WITH_INTERNATIONAL
# include "BLI_threads.h"
# include "boost_locale_wrapper.h"
-#endif /* WITH_INTERNATIONAL */
+#endif /* WITH_INTERNATIONAL */
bool BLT_is_default_context(const char *msgctxt)
{
- /* We use the "short" test, a more complete one could be:
- * return (!msgctxt || !msgctxt[0] || STREQ(msgctxt, BLT_I18NCONTEXT_DEFAULT_BPYRNA))
- */
- /* Note: trying without the void string check for now, it *should* not be necessary... */
- return (!msgctxt || msgctxt[0] == BLT_I18NCONTEXT_DEFAULT_BPYRNA[0]);
+ /* We use the "short" test, a more complete one could be:
+ * return (!msgctxt || !msgctxt[0] || STREQ(msgctxt, BLT_I18NCONTEXT_DEFAULT_BPYRNA))
+ */
+ /* Note: trying without the void string check for now, it *should* not be necessary... */
+ return (!msgctxt || msgctxt[0] == BLT_I18NCONTEXT_DEFAULT_BPYRNA[0]);
}
const char *BLT_pgettext(const char *msgctxt, const char *msgid)
{
#ifdef WITH_INTERNATIONAL
- const char *ret = msgid;
-
- if (msgid && msgid[0]) {
- if (BLT_is_default_context(msgctxt)) {
- msgctxt = BLT_I18NCONTEXT_DEFAULT;
- }
- ret = bl_locale_pgettext(msgctxt, msgid);
- /* We assume if the returned string is the same (memory level) as the msgid, no translation was found,
- * and we can try py scripts' ones!
- */
-#ifdef WITH_PYTHON
- if (ret == msgid) {
- ret = BPY_app_translations_py_pgettext(msgctxt, msgid);
- }
-#endif
- }
-
- return ret;
+ const char *ret = msgid;
+
+ if (msgid && msgid[0]) {
+ if (BLT_is_default_context(msgctxt)) {
+ msgctxt = BLT_I18NCONTEXT_DEFAULT;
+ }
+ ret = bl_locale_pgettext(msgctxt, msgid);
+ /* We assume if the returned string is the same (memory level) as the msgid, no translation was found,
+ * and we can try py scripts' ones!
+ */
+# ifdef WITH_PYTHON
+ if (ret == msgid) {
+ ret = BPY_app_translations_py_pgettext(msgctxt, msgid);
+ }
+# endif
+ }
+
+ return ret;
#else
- (void)msgctxt;
- return msgid;
+ (void)msgctxt;
+ return msgid;
#endif
}
bool BLT_translate(void)
{
#ifdef WITH_INTERNATIONAL
- return BLI_thread_is_main() && (U.transopts & USER_DOTRANSLATE);
+ return BLI_thread_is_main() && (U.transopts & USER_DOTRANSLATE);
#else
- return false;
+ return false;
#endif
}
bool BLT_translate_iface(void)
{
#ifdef WITH_INTERNATIONAL
- return BLT_translate() && (U.transopts & USER_TR_IFACE);
+ return BLT_translate() && (U.transopts & USER_TR_IFACE);
#else
- return false;
+ return false;
#endif
}
bool BLT_translate_tooltips(void)
{
#ifdef WITH_INTERNATIONAL
- return BLT_translate() && (U.transopts & USER_TR_TOOLTIPS);
+ return BLT_translate() && (U.transopts & USER_TR_TOOLTIPS);
#else
- return false;
+ return false;
#endif
}
bool BLT_translate_new_dataname(void)
{
#ifdef WITH_INTERNATIONAL
- return BLT_translate() && (U.transopts & USER_TR_NEWDATANAME);
+ return BLT_translate() && (U.transopts & USER_TR_NEWDATANAME);
#else
- return false;
+ return false;
#endif
}
const char *BLT_translate_do(const char *msgctxt, const char *msgid)
{
#ifdef WITH_INTERNATIONAL
- if (BLT_translate()) {
- return BLT_pgettext(msgctxt, msgid);
- }
- else {
- return msgid;
- }
+ if (BLT_translate()) {
+ return BLT_pgettext(msgctxt, msgid);
+ }
+ else {
+ return msgid;
+ }
#else
- (void)msgctxt;
- return msgid;
+ (void)msgctxt;
+ return msgid;
#endif
}
const char *BLT_translate_do_iface(const char *msgctxt, const char *msgid)
{
#ifdef WITH_INTERNATIONAL
- if (BLT_translate_iface()) {
- return BLT_pgettext(msgctxt, msgid);
- }
- else {
- return msgid;
- }
+ if (BLT_translate_iface()) {
+ return BLT_pgettext(msgctxt, msgid);
+ }
+ else {
+ return msgid;
+ }
#else
- (void)msgctxt;
- return msgid;
+ (void)msgctxt;
+ return msgid;
#endif
}
const char *BLT_translate_do_tooltip(const char *msgctxt, const char *msgid)
{
#ifdef WITH_INTERNATIONAL
- if (BLT_translate_tooltips()) {
- return BLT_pgettext(msgctxt, msgid);
- }
- else {
- return msgid;
- }
+ if (BLT_translate_tooltips()) {
+ return BLT_pgettext(msgctxt, msgid);
+ }
+ else {
+ return msgid;
+ }
#else
- (void)msgctxt;
- return msgid;
+ (void)msgctxt;
+ return msgid;
#endif
}
const char *BLT_translate_do_new_dataname(const char *msgctxt, const char *msgid)
{
#ifdef WITH_INTERNATIONAL
- if (BLT_translate_new_dataname()) {
- return BLT_pgettext(msgctxt, msgid);
- }
- else {
- return msgid;
- }
+ if (BLT_translate_new_dataname()) {
+ return BLT_pgettext(msgctxt, msgid);
+ }
+ else {
+ return msgid;
+ }
#else
- (void)msgctxt;
- return msgid;
+ (void)msgctxt;
+ return msgid;
#endif
}
diff --git a/source/blender/blentranslation/msgfmt/CMakeLists.txt b/source/blender/blentranslation/msgfmt/CMakeLists.txt
index 48537604157..1b46efb1bb5 100644
--- a/source/blender/blentranslation/msgfmt/CMakeLists.txt
+++ b/source/blender/blentranslation/msgfmt/CMakeLists.txt
@@ -22,12 +22,12 @@
# Build msgfmt executable
blender_include_dirs(
- ../../../../intern/guardedalloc
- ../../blenlib
+ ../../../../intern/guardedalloc
+ ../../blenlib
)
set(SRC
- msgfmt.c
+ msgfmt.c
)
add_cc_flags_custom_test(msgfmt)
@@ -38,7 +38,7 @@ target_link_libraries(msgfmt bf_blenlib)
target_link_libraries(msgfmt bf_intern_guardedalloc)
if(WIN32)
- target_link_libraries(msgfmt bf_intern_utfconv)
+ target_link_libraries(msgfmt bf_intern_utfconv)
endif()
target_link_libraries(msgfmt ${ZLIB_LIBRARIES})
diff --git a/source/blender/blentranslation/msgfmt/msgfmt.c b/source/blender/blentranslation/msgfmt/msgfmt.c
index 69d7ecb14a5..6beaef74a9f 100644
--- a/source/blender/blentranslation/msgfmt/msgfmt.c
+++ b/source/blender/blentranslation/msgfmt/msgfmt.c
@@ -42,421 +42,420 @@
#include "MEM_guardedalloc.h"
-
/* Stupid stub necessary because some BLI files includes winstuff.h, which uses G a bit... */
#ifdef WIN32
- typedef struct Global {
- void *dummy;
- } Global;
+typedef struct Global {
+ void *dummy;
+} Global;
- Global G;
+Global G;
#endif
-
/* We cannot use NULL char until ultimate step, would give nightmare to our C string processing...
* Using one of the UTF-8 invalid bytes (as per our BLI string_utf8.c) */
#define NULLSEP_STR "\xff"
#define NULLSEP_CHR '\xff'
typedef enum {
- SECTION_NONE = 0,
- SECTION_CTX = 1,
- SECTION_ID = 2,
- SECTION_STR = 3,
+ SECTION_NONE = 0,
+ SECTION_CTX = 1,
+ SECTION_ID = 2,
+ SECTION_STR = 3,
} eSectionType;
typedef struct Message {
- DynStr *ctxt;
- DynStr *id;
- DynStr *str;
+ DynStr *ctxt;
+ DynStr *id;
+ DynStr *str;
- bool is_fuzzy;
+ bool is_fuzzy;
} Message;
static char *trim(char *str)
{
- const size_t len = strlen(str);
- size_t i;
+ const size_t len = strlen(str);
+ size_t i;
- if (len == 0) {
- return str;
- }
+ if (len == 0) {
+ return str;
+ }
- for (i = 0; i < len && ELEM(str[0], ' ', '\t', '\n'); str++, i++);
+ for (i = 0; i < len && ELEM(str[0], ' ', '\t', '\n'); str++, i++)
+ ;
- char *end = &str[len - 1 - i];
- for (i = len; i > 0 && ELEM(end[0], ' ', '\t', '\n'); end--, i--);
- end[1] = '\0';
+ char *end = &str[len - 1 - i];
+ for (i = len; i > 0 && ELEM(end[0], ' ', '\t', '\n'); end--, i--)
+ ;
+ end[1] = '\0';
- return str;
+ return str;
}
static char *unescape(char *str)
{
- char *curr, *next;
- for (curr = next = str; next[0] != '\0'; curr++, next++) {
- if (next[0] == '\\') {
- switch (next[1]) {
- case '\0':
- /* Get rid of trailing escape char... */
- curr--;
- break;
- case '\\':
- *curr = '\\';
- next++;
- break;
- case 'n':
- *curr = '\n';
- next++;
- break;
- case 't':
- *curr = '\t';
- next++;
- break;
- default:
- /* Get rid of useless escape char. */
- next++;
- *curr = *next;
- }
- }
- else if (curr != next) {
- *curr = *next;
- }
- }
- *curr = '\0';
-
- if (str[0] == '"' && *(curr - 1) == '"') {
- *(curr - 1) = '\0';
- return str + 1;
- }
- return str;
+ char *curr, *next;
+ for (curr = next = str; next[0] != '\0'; curr++, next++) {
+ if (next[0] == '\\') {
+ switch (next[1]) {
+ case '\0':
+ /* Get rid of trailing escape char... */
+ curr--;
+ break;
+ case '\\':
+ *curr = '\\';
+ next++;
+ break;
+ case 'n':
+ *curr = '\n';
+ next++;
+ break;
+ case 't':
+ *curr = '\t';
+ next++;
+ break;
+ default:
+ /* Get rid of useless escape char. */
+ next++;
+ *curr = *next;
+ }
+ }
+ else if (curr != next) {
+ *curr = *next;
+ }
+ }
+ *curr = '\0';
+
+ if (str[0] == '"' && *(curr - 1) == '"') {
+ *(curr - 1) = '\0';
+ return str + 1;
+ }
+ return str;
}
static int qsort_str_cmp(const void *a, const void *b)
{
- return strcmp(*(const char **)a, *(const char **)b);
+ return strcmp(*(const char **)a, *(const char **)b);
}
static char **get_keys_sorted(GHash *messages, const uint32_t num_keys)
{
- GHashIterator iter;
+ GHashIterator iter;
- char **keys = MEM_mallocN(sizeof(*keys) * num_keys, __func__);
- char **k = keys;
+ char **keys = MEM_mallocN(sizeof(*keys) * num_keys, __func__);
+ char **k = keys;
- GHASH_ITER(iter, messages) {
- *k = BLI_ghashIterator_getKey(&iter);
- k++;
- }
+ GHASH_ITER (iter, messages) {
+ *k = BLI_ghashIterator_getKey(&iter);
+ k++;
+ }
- qsort(keys, num_keys, sizeof(*keys), qsort_str_cmp);
+ qsort(keys, num_keys, sizeof(*keys), qsort_str_cmp);
- return keys;
+ return keys;
}
BLI_INLINE size_t uint32_to_bytes(const int value, char *bytes)
{
- size_t i;
- for (i = 0; i < sizeof(value); i++) {
- bytes[i] = (char) ((value >> ((int)i * 8)) & 0xff);
- }
- return i;
+ size_t i;
+ for (i = 0; i < sizeof(value); i++) {
+ bytes[i] = (char)((value >> ((int)i * 8)) & 0xff);
+ }
+ return i;
}
BLI_INLINE size_t msg_to_bytes(char *msg, char *bytes, uint32_t size)
{
- /* Note that we also perform replacing of our NULLSEP placeholder by real NULL char... */
- size_t i;
- for (i = 0; i < size; i++, msg++, bytes++) {
- *bytes = (*msg == NULLSEP_CHR) ? '\0' : *msg;
- }
- return i;
+ /* Note that we also perform replacing of our NULLSEP placeholder by real NULL char... */
+ size_t i;
+ for (i = 0; i < size; i++, msg++, bytes++) {
+ *bytes = (*msg == NULLSEP_CHR) ? '\0' : *msg;
+ }
+ return i;
}
typedef struct Offset {
- uint32_t key_offset, key_len, val_offset, val_len;
+ uint32_t key_offset, key_len, val_offset, val_len;
} Offset;
/* Return the generated binary output. */
static char *generate(GHash *messages, size_t *r_output_size)
{
- const uint32_t num_keys = BLI_ghash_len(messages);
-
- /* Get list of sorted keys. */
- char **keys = get_keys_sorted(messages, num_keys);
- char **vals = MEM_mallocN(sizeof(*vals) * num_keys, __func__);
- uint32_t tot_keys_len = 0;
- uint32_t tot_vals_len = 0;
-
- Offset *offsets = MEM_mallocN(sizeof(*offsets) * num_keys, __func__);
-
- for (int i = 0; i < num_keys; i++) {
- Offset *off = &offsets[i];
-
- vals[i] = BLI_ghash_lookup(messages, keys[i]);
-
- /* For each string, we need size and file offset.
- * Each string is NULL terminated; the NULL does not count into the size. */
- off->key_offset = tot_keys_len;
- off->key_len = (uint32_t)strlen(keys[i]);
- tot_keys_len += off->key_len + 1;
-
- off->val_offset = tot_vals_len;
- off->val_len = (uint32_t)strlen(vals[i]);
- tot_vals_len += off->val_len + 1;
- }
-
- /* The header is 7 32-bit unsigned integers. then comes the keys index table, then the values index table. */
- const uint32_t idx_keystart = 7 * 4;
- const uint32_t idx_valstart = idx_keystart + 8 * num_keys;
- /* We don't use hash tables, so the keys start right after the index tables. */
- const uint32_t keystart = idx_valstart + 8 * num_keys;
- /* and the values start after the keys */
- const uint32_t valstart = keystart + tot_keys_len;
-
- /* Final buffer representing the binary MO file. */
- *r_output_size = valstart + tot_vals_len;
- char *output = MEM_mallocN(*r_output_size, __func__);
- char *h = output;
- char *ik = output + idx_keystart;
- char *iv = output + idx_valstart;
- char *k = output + keystart;
- char *v = output + valstart;
-
- h += uint32_to_bytes(0x950412de, h); /* Magic */
- h += uint32_to_bytes(0x0, h); /* Version */
- h += uint32_to_bytes(num_keys, h); /* Number of entries */
- h += uint32_to_bytes(idx_keystart, h); /* Start of key index */
- h += uint32_to_bytes(idx_valstart, h); /* Start of value index */
- h += uint32_to_bytes(0, h); /* Size of hash table */
- h += uint32_to_bytes(0, h); /* Offset of hash table */
-
- BLI_assert(h == ik);
-
- for (int i = 0; i < num_keys; i++) {
- Offset *off = &offsets[i];
-
- /* The index table first has the list of keys, then the list of values.
- * Each entry has first the size of the string, then the file offset. */
- ik += uint32_to_bytes(off->key_len, ik);
- ik += uint32_to_bytes(off->key_offset + keystart, ik);
- iv += uint32_to_bytes(off->val_len, iv);
- iv += uint32_to_bytes(off->val_offset + valstart, iv);
-
- k += msg_to_bytes(keys[i], k, off->key_len + 1);
- v += msg_to_bytes(vals[i], v, off->val_len + 1);
- }
-
- BLI_assert(ik == output + idx_valstart);
- BLI_assert(iv == output + keystart);
- BLI_assert(k == output + valstart);
-
- MEM_freeN(keys);
- MEM_freeN(vals);
- MEM_freeN(offsets);
-
- return output;
+ const uint32_t num_keys = BLI_ghash_len(messages);
+
+ /* Get list of sorted keys. */
+ char **keys = get_keys_sorted(messages, num_keys);
+ char **vals = MEM_mallocN(sizeof(*vals) * num_keys, __func__);
+ uint32_t tot_keys_len = 0;
+ uint32_t tot_vals_len = 0;
+
+ Offset *offsets = MEM_mallocN(sizeof(*offsets) * num_keys, __func__);
+
+ for (int i = 0; i < num_keys; i++) {
+ Offset *off = &offsets[i];
+
+ vals[i] = BLI_ghash_lookup(messages, keys[i]);
+
+ /* For each string, we need size and file offset.
+ * Each string is NULL terminated; the NULL does not count into the size. */
+ off->key_offset = tot_keys_len;
+ off->key_len = (uint32_t)strlen(keys[i]);
+ tot_keys_len += off->key_len + 1;
+
+ off->val_offset = tot_vals_len;
+ off->val_len = (uint32_t)strlen(vals[i]);
+ tot_vals_len += off->val_len + 1;
+ }
+
+ /* The header is 7 32-bit unsigned integers. then comes the keys index table, then the values index table. */
+ const uint32_t idx_keystart = 7 * 4;
+ const uint32_t idx_valstart = idx_keystart + 8 * num_keys;
+ /* We don't use hash tables, so the keys start right after the index tables. */
+ const uint32_t keystart = idx_valstart + 8 * num_keys;
+ /* and the values start after the keys */
+ const uint32_t valstart = keystart + tot_keys_len;
+
+ /* Final buffer representing the binary MO file. */
+ *r_output_size = valstart + tot_vals_len;
+ char *output = MEM_mallocN(*r_output_size, __func__);
+ char *h = output;
+ char *ik = output + idx_keystart;
+ char *iv = output + idx_valstart;
+ char *k = output + keystart;
+ char *v = output + valstart;
+
+ h += uint32_to_bytes(0x950412de, h); /* Magic */
+ h += uint32_to_bytes(0x0, h); /* Version */
+ h += uint32_to_bytes(num_keys, h); /* Number of entries */
+ h += uint32_to_bytes(idx_keystart, h); /* Start of key index */
+ h += uint32_to_bytes(idx_valstart, h); /* Start of value index */
+ h += uint32_to_bytes(0, h); /* Size of hash table */
+ h += uint32_to_bytes(0, h); /* Offset of hash table */
+
+ BLI_assert(h == ik);
+
+ for (int i = 0; i < num_keys; i++) {
+ Offset *off = &offsets[i];
+
+ /* The index table first has the list of keys, then the list of values.
+ * Each entry has first the size of the string, then the file offset. */
+ ik += uint32_to_bytes(off->key_len, ik);
+ ik += uint32_to_bytes(off->key_offset + keystart, ik);
+ iv += uint32_to_bytes(off->val_len, iv);
+ iv += uint32_to_bytes(off->val_offset + valstart, iv);
+
+ k += msg_to_bytes(keys[i], k, off->key_len + 1);
+ v += msg_to_bytes(vals[i], v, off->val_len + 1);
+ }
+
+ BLI_assert(ik == output + idx_valstart);
+ BLI_assert(iv == output + keystart);
+ BLI_assert(k == output + valstart);
+
+ MEM_freeN(keys);
+ MEM_freeN(vals);
+ MEM_freeN(offsets);
+
+ return output;
}
/* Add a non-fuzzy translation to the dictionary. */
static void add(GHash *messages, MemArena *memarena, const Message *msg)
{
- const size_t msgctxt_len = (size_t)BLI_dynstr_get_len(msg->ctxt);
- const size_t msgid_len = (size_t)BLI_dynstr_get_len(msg->id);
- const size_t msgstr_len = (size_t)BLI_dynstr_get_len(msg->str);
- const size_t msgkey_len = msgid_len + ((msgctxt_len == 0) ? 0 : msgctxt_len + 1);
-
- if (!msg->is_fuzzy && msgstr_len != 0) {
- char *msgkey = BLI_memarena_alloc(memarena, sizeof(*msgkey) * (msgkey_len + 1));
- char *msgstr = BLI_memarena_alloc(memarena, sizeof(*msgstr) * (msgstr_len + 1));
-
- if (msgctxt_len != 0) {
- BLI_dynstr_get_cstring_ex(msg->ctxt, msgkey);
- msgkey[msgctxt_len] = '\x04'; /* Context/msgid separator */
- BLI_dynstr_get_cstring_ex(msg->id, &msgkey[msgctxt_len + 1]);
- }
- else {
- BLI_dynstr_get_cstring_ex(msg->id, msgkey);
- }
-
- BLI_dynstr_get_cstring_ex(msg->str, msgstr);
-
- BLI_ghash_insert(messages, msgkey, msgstr);
- }
+ const size_t msgctxt_len = (size_t)BLI_dynstr_get_len(msg->ctxt);
+ const size_t msgid_len = (size_t)BLI_dynstr_get_len(msg->id);
+ const size_t msgstr_len = (size_t)BLI_dynstr_get_len(msg->str);
+ const size_t msgkey_len = msgid_len + ((msgctxt_len == 0) ? 0 : msgctxt_len + 1);
+
+ if (!msg->is_fuzzy && msgstr_len != 0) {
+ char *msgkey = BLI_memarena_alloc(memarena, sizeof(*msgkey) * (msgkey_len + 1));
+ char *msgstr = BLI_memarena_alloc(memarena, sizeof(*msgstr) * (msgstr_len + 1));
+
+ if (msgctxt_len != 0) {
+ BLI_dynstr_get_cstring_ex(msg->ctxt, msgkey);
+ msgkey[msgctxt_len] = '\x04'; /* Context/msgid separator */
+ BLI_dynstr_get_cstring_ex(msg->id, &msgkey[msgctxt_len + 1]);
+ }
+ else {
+ BLI_dynstr_get_cstring_ex(msg->id, msgkey);
+ }
+
+ BLI_dynstr_get_cstring_ex(msg->str, msgstr);
+
+ BLI_ghash_insert(messages, msgkey, msgstr);
+ }
}
-
static void clear(Message *msg)
{
- BLI_dynstr_clear(msg->ctxt);
- BLI_dynstr_clear(msg->id);
- BLI_dynstr_clear(msg->str);
- msg->is_fuzzy = false;
+ BLI_dynstr_clear(msg->ctxt);
+ BLI_dynstr_clear(msg->id);
+ BLI_dynstr_clear(msg->str);
+ msg->is_fuzzy = false;
}
static int make(const char *input_file_name, const char *output_file_name)
{
- GHash *messages = BLI_ghash_new(BLI_ghashutil_strhash_p_murmur, BLI_ghashutil_strcmp, __func__);
- MemArena *msgs_memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
-
- const char *msgctxt_kw = "msgctxt";
- const char *msgid_kw = "msgid";
- const char *msgid_plural_kw = "msgid_plural";
- const char *msgstr_kw = "msgstr";
- const size_t msgctxt_len = strlen(msgctxt_kw);
- const size_t msgid_len = strlen(msgid_kw);
- const size_t msgid_plural_len = strlen(msgid_plural_kw);
- const size_t msgstr_len = strlen(msgstr_kw);
-
- /* Note: For now, we assume file encoding is always utf-8. */
-
- eSectionType section = SECTION_NONE;
- bool is_plural = false;
-
- Message msg = {
- .ctxt = BLI_dynstr_new_memarena(),
- .id = BLI_dynstr_new_memarena(),
- .str = BLI_dynstr_new_memarena(),
- .is_fuzzy = false,
- };
-
- LinkNode *input_file_lines = BLI_file_read_as_lines(input_file_name);
- LinkNode *ifl = input_file_lines;
-
- /* Parse the catalog. */
- for (int lno = 1; ifl; ifl = ifl->next, lno++) {
- char *l = ifl->link;
- const bool is_comment = (l[0] == '#');
- /* If we get a comment line after a msgstr, this is a new entry. */
- if (is_comment) {
- if (section == SECTION_STR) {
- add(messages, msgs_memarena, &msg);
- clear(&msg);
- section = SECTION_NONE;
- }
- /* Record a fuzzy mark. */
- if (l[1] == ',' && strstr(l, "fuzzy") != NULL) {
- msg.is_fuzzy = true;
- }
- /* Skip comments */
- continue;
- }
- if (strstr(l, msgctxt_kw) == l) {
- if (section == SECTION_STR) {
- /* New message, output previous section. */
- add(messages, msgs_memarena, &msg);
- }
- if (!ELEM(section, SECTION_NONE, SECTION_STR)) {
- printf("msgctxt not at start of new message on %s:%d\n", input_file_name, lno);
- return EXIT_FAILURE;
- }
- section = SECTION_CTX;
- l = l + msgctxt_len;
- clear(&msg);
- }
- else if (strstr(l, msgid_plural_kw) == l) {
- /* This is a message with plural forms. */
- if (section != SECTION_ID) {
- printf("msgid_plural not preceeded by msgid on %s:%d\n", input_file_name, lno);
- return EXIT_FAILURE;
- }
- l = l + msgid_plural_len;
- BLI_dynstr_append(msg.id, NULLSEP_STR); /* separator of singular and plural */
- is_plural = true;
- }
- else if (strstr(l, msgid_kw) == l) {
- if (section == SECTION_STR) {
- add(messages, msgs_memarena, &msg);
- }
- if (section != SECTION_CTX) {
- clear(&msg);
- }
- section = SECTION_ID;
- l = l + msgid_len;
- is_plural = false;
- }
- else if (strstr(l, msgstr_kw) == l) {
- l = l + msgstr_len;
- // Now we are in a msgstr section
- section = SECTION_STR;
- if (l[0] == '[') {
- if (!is_plural) {
- printf("plural without msgid_plural on %s:%d\n", input_file_name, lno);
- return EXIT_FAILURE;
- }
- if ((l = strchr(l, ']')) == NULL) {
- printf("Syntax error on %s:%d\n", input_file_name, lno);
- return EXIT_FAILURE;
- }
- if (BLI_dynstr_get_len(msg.str) != 0) {
- BLI_dynstr_append(msg.str, NULLSEP_STR); /* Separator of the various plural forms. */
- }
- }
- else {
- if (is_plural) {
- printf("indexed msgstr required for plural on %s:%d\n", input_file_name, lno);
- return EXIT_FAILURE;
- }
- }
- }
- /* Skip empty lines. */
- l = trim(l);
- if (l[0] == '\0') {
- if (section == SECTION_STR) {
- add(messages, msgs_memarena, &msg);
- clear(&msg);
- }
- section = SECTION_NONE;
- continue;
- }
- l = unescape(l);
- if (section == SECTION_CTX) {
- BLI_dynstr_append(msg.ctxt, l);
- }
- else if (section == SECTION_ID) {
- BLI_dynstr_append(msg.id, l);
- }
- else if (section == SECTION_STR) {
- BLI_dynstr_append(msg.str, l);
- }
- else {
- printf("Syntax error on %s:%d\n", input_file_name, lno);
- return EXIT_FAILURE;
- }
- }
- /* Add last entry */
- if (section == SECTION_STR) {
- add(messages, msgs_memarena, &msg);
- }
-
- BLI_dynstr_free(msg.ctxt);
- BLI_dynstr_free(msg.id);
- BLI_dynstr_free(msg.str);
- BLI_file_free_lines(input_file_lines);
-
- /* Compute output */
- size_t output_size;
- char *output = generate(messages, &output_size);
-
- FILE *fp = BLI_fopen(output_file_name, "wb");
- fwrite(output, 1, output_size, fp);
- fclose(fp);
-
- MEM_freeN(output);
- BLI_ghash_free(messages, NULL, NULL);
- BLI_memarena_free(msgs_memarena);
-
- return EXIT_SUCCESS;
+ GHash *messages = BLI_ghash_new(BLI_ghashutil_strhash_p_murmur, BLI_ghashutil_strcmp, __func__);
+ MemArena *msgs_memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+
+ const char *msgctxt_kw = "msgctxt";
+ const char *msgid_kw = "msgid";
+ const char *msgid_plural_kw = "msgid_plural";
+ const char *msgstr_kw = "msgstr";
+ const size_t msgctxt_len = strlen(msgctxt_kw);
+ const size_t msgid_len = strlen(msgid_kw);
+ const size_t msgid_plural_len = strlen(msgid_plural_kw);
+ const size_t msgstr_len = strlen(msgstr_kw);
+
+ /* Note: For now, we assume file encoding is always utf-8. */
+
+ eSectionType section = SECTION_NONE;
+ bool is_plural = false;
+
+ Message msg = {
+ .ctxt = BLI_dynstr_new_memarena(),
+ .id = BLI_dynstr_new_memarena(),
+ .str = BLI_dynstr_new_memarena(),
+ .is_fuzzy = false,
+ };
+
+ LinkNode *input_file_lines = BLI_file_read_as_lines(input_file_name);
+ LinkNode *ifl = input_file_lines;
+
+ /* Parse the catalog. */
+ for (int lno = 1; ifl; ifl = ifl->next, lno++) {
+ char *l = ifl->link;
+ const bool is_comment = (l[0] == '#');
+ /* If we get a comment line after a msgstr, this is a new entry. */
+ if (is_comment) {
+ if (section == SECTION_STR) {
+ add(messages, msgs_memarena, &msg);
+ clear(&msg);
+ section = SECTION_NONE;
+ }
+ /* Record a fuzzy mark. */
+ if (l[1] == ',' && strstr(l, "fuzzy") != NULL) {
+ msg.is_fuzzy = true;
+ }
+ /* Skip comments */
+ continue;
+ }
+ if (strstr(l, msgctxt_kw) == l) {
+ if (section == SECTION_STR) {
+ /* New message, output previous section. */
+ add(messages, msgs_memarena, &msg);
+ }
+ if (!ELEM(section, SECTION_NONE, SECTION_STR)) {
+ printf("msgctxt not at start of new message on %s:%d\n", input_file_name, lno);
+ return EXIT_FAILURE;
+ }
+ section = SECTION_CTX;
+ l = l + msgctxt_len;
+ clear(&msg);
+ }
+ else if (strstr(l, msgid_plural_kw) == l) {
+ /* This is a message with plural forms. */
+ if (section != SECTION_ID) {
+ printf("msgid_plural not preceeded by msgid on %s:%d\n", input_file_name, lno);
+ return EXIT_FAILURE;
+ }
+ l = l + msgid_plural_len;
+ BLI_dynstr_append(msg.id, NULLSEP_STR); /* separator of singular and plural */
+ is_plural = true;
+ }
+ else if (strstr(l, msgid_kw) == l) {
+ if (section == SECTION_STR) {
+ add(messages, msgs_memarena, &msg);
+ }
+ if (section != SECTION_CTX) {
+ clear(&msg);
+ }
+ section = SECTION_ID;
+ l = l + msgid_len;
+ is_plural = false;
+ }
+ else if (strstr(l, msgstr_kw) == l) {
+ l = l + msgstr_len;
+ // Now we are in a msgstr section
+ section = SECTION_STR;
+ if (l[0] == '[') {
+ if (!is_plural) {
+ printf("plural without msgid_plural on %s:%d\n", input_file_name, lno);
+ return EXIT_FAILURE;
+ }
+ if ((l = strchr(l, ']')) == NULL) {
+ printf("Syntax error on %s:%d\n", input_file_name, lno);
+ return EXIT_FAILURE;
+ }
+ if (BLI_dynstr_get_len(msg.str) != 0) {
+ BLI_dynstr_append(msg.str, NULLSEP_STR); /* Separator of the various plural forms. */
+ }
+ }
+ else {
+ if (is_plural) {
+ printf("indexed msgstr required for plural on %s:%d\n", input_file_name, lno);
+ return EXIT_FAILURE;
+ }
+ }
+ }
+ /* Skip empty lines. */
+ l = trim(l);
+ if (l[0] == '\0') {
+ if (section == SECTION_STR) {
+ add(messages, msgs_memarena, &msg);
+ clear(&msg);
+ }
+ section = SECTION_NONE;
+ continue;
+ }
+ l = unescape(l);
+ if (section == SECTION_CTX) {
+ BLI_dynstr_append(msg.ctxt, l);
+ }
+ else if (section == SECTION_ID) {
+ BLI_dynstr_append(msg.id, l);
+ }
+ else if (section == SECTION_STR) {
+ BLI_dynstr_append(msg.str, l);
+ }
+ else {
+ printf("Syntax error on %s:%d\n", input_file_name, lno);
+ return EXIT_FAILURE;
+ }
+ }
+ /* Add last entry */
+ if (section == SECTION_STR) {
+ add(messages, msgs_memarena, &msg);
+ }
+
+ BLI_dynstr_free(msg.ctxt);
+ BLI_dynstr_free(msg.id);
+ BLI_dynstr_free(msg.str);
+ BLI_file_free_lines(input_file_lines);
+
+ /* Compute output */
+ size_t output_size;
+ char *output = generate(messages, &output_size);
+
+ FILE *fp = BLI_fopen(output_file_name, "wb");
+ fwrite(output, 1, output_size, fp);
+ fclose(fp);
+
+ MEM_freeN(output);
+ BLI_ghash_free(messages, NULL, NULL);
+ BLI_memarena_free(msgs_memarena);
+
+ return EXIT_SUCCESS;
}
int main(int argc, char **argv)
{
- if (argc != 3) {
- printf("Usage: %s <input.po> <output.mo>\n", argv[0]);
- return EXIT_FAILURE;
- }
- const char *input_file = argv[1];
- const char *output_file = argv[2];
-
- return make(input_file, output_file);
+ if (argc != 3) {
+ printf("Usage: %s <input.po> <output.mo>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+ const char *input_file = argv[1];
+ const char *output_file = argv[2];
+
+ return make(input_file, output_file);
}