I18n: move to C++ #110269
@ -13,8 +13,8 @@ set(INC_SYS
|
||||
)
|
||||
|
||||
set(SRC
|
||||
intern/blt_lang.c
|
||||
intern/blt_translation.c
|
||||
intern/blt_lang.cc
|
||||
intern/blt_translation.cc
|
||||
|
||||
BLT_lang.h
|
||||
BLT_translation.h
|
||||
|
@ -41,9 +41,9 @@
|
||||
# include "boost_locale_wrapper.h"
|
||||
|
||||
/* Locale options. */
|
||||
static const char **locales = NULL;
|
||||
static const char **locales = nullptr;
|
||||
static int num_locales = 0;
|
||||
static EnumPropertyItem *locales_menu = NULL;
|
||||
static EnumPropertyItem *locales_menu = nullptr;
|
||||
static int num_locales_menu = 0;
|
||||
|
||||
static void free_locales(void)
|
||||
@ -57,7 +57,7 @@ static void free_locales(void)
|
||||
}
|
||||
|
||||
MEM_freeN((void *)locales);
|
||||
locales = NULL;
|
||||
locales = nullptr;
|
||||
}
|
||||
MEM_SAFE_FREE(locales_menu);
|
||||
num_locales = num_locales_menu = 0;
|
||||
@ -67,7 +67,7 @@ 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;
|
||||
LinkNode *lines = nullptr, *line;
|
||||
char *str;
|
||||
int idx = 0;
|
||||
|
||||
@ -97,12 +97,13 @@ static void fill_locales(void)
|
||||
num_locales_menu++; /* The "closing" void item... */
|
||||
|
||||
/* And now, build locales and locale_menu! */
|
||||
locales_menu = MEM_callocN(num_locales_menu * sizeof(EnumPropertyItem), __func__);
|
||||
locales_menu = static_cast<EnumPropertyItem *>(
|
||||
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! */
|
||||
* as LOCALE macro uses nullptr locales as invalid marker! */
|
||||
if (num_locales > 0) {
|
||||
locales = MEM_callocN(num_locales * sizeof(char *), __func__);
|
||||
locales = static_cast<const char **>(MEM_callocN(num_locales * sizeof(char *), __func__));
|
||||
while (line) {
|
||||
int id;
|
||||
char *loc, *sep1, *sep2, *sep3;
|
||||
@ -160,7 +161,7 @@ static void fill_locales(void)
|
||||
}
|
||||
|
||||
/* Add closing item to menu! */
|
||||
locales_menu[idx].identifier = NULL;
|
||||
locales_menu[idx].identifier = nullptr;
|
||||
locales_menu[idx].value = locales_menu[idx].icon = 0;
|
||||
locales_menu[idx].name = locales_menu[idx].description = "";
|
||||
|
||||
@ -173,7 +174,7 @@ EnumPropertyItem *BLT_lang_RNA_enum_properties(void)
|
||||
#ifdef WITH_INTERNATIONAL
|
||||
return locales_menu;
|
||||
#else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -183,7 +184,7 @@ void BLT_lang_init(void)
|
||||
const char *const messagepath = BKE_appdir_folder_id(BLENDER_DATAFILES, "locale");
|
||||
#endif
|
||||
|
||||
/* Make sure LANG is correct and wouldn't cause #std::runtime_error. */
|
||||
/* Make sure LANG is correct and wouldn't cause #std::runtime_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 will be no runtime
|
||||
@ -197,11 +198,11 @@ void BLT_lang_init(void)
|
||||
* 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);
|
||||
if (lang != nullptr) {
|
||||
char *old_locale = setlocale(LC_ALL, nullptr);
|
||||
/* Make a copy so subsequent #setlocale() doesn't interfere. */
|
||||
old_locale = BLI_strdup(old_locale);
|
||||
if (setlocale(LC_ALL, lang) == NULL) {
|
||||
if (setlocale(LC_ALL, lang) == nullptr) {
|
||||
setenv("LANG", "C", 1);
|
||||
printf("Warning: Falling back to the standard locale (\"C\")\n");
|
||||
}
|
||||
@ -241,12 +242,12 @@ 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;
|
||||
const char *short_locale_utf8 = nullptr;
|
||||
|
||||
/* We want to avoid locales like '.UTF-8'! */
|
||||
if (short_locale[0]) {
|
||||
/* Hooray! Encoding needs to be placed *before* variant! */
|
||||
char *variant = strchr(short_locale, '@');
|
||||
const 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);
|
||||
@ -293,7 +294,8 @@ void BLT_lang_locale_explode(const char *locale,
|
||||
char **language_country,
|
||||
char **language_variant)
|
||||
{
|
||||
char *m1, *m2, *_t = NULL;
|
||||
const char *m1, *m2;
|
||||
char *_t = nullptr;
|
||||
|
||||
m1 = strchr(locale, '_');
|
||||
m2 = strchr(locale, '@');
|
||||
@ -314,7 +316,7 @@ void BLT_lang_locale_explode(const char *locale,
|
||||
*country = m2 ? BLI_strdupn(m1 + 1, m2 - (m1 + 1)) : BLI_strdup(m1 + 1);
|
||||
}
|
||||
else {
|
||||
*country = NULL;
|
||||
*country = nullptr;
|
||||
}
|
||||
}
|
||||
if (variant) {
|
||||
@ -322,7 +324,7 @@ void BLT_lang_locale_explode(const char *locale,
|
||||
*variant = BLI_strdup(m2 + 1);
|
||||
}
|
||||
else {
|
||||
*variant = NULL;
|
||||
*variant = nullptr;
|
||||
}
|
||||
}
|
||||
if (language_country) {
|
||||
@ -330,7 +332,7 @@ void BLT_lang_locale_explode(const char *locale,
|
||||
*language_country = m2 ? BLI_strdupn(locale, m2 - locale) : BLI_strdup(locale);
|
||||
}
|
||||
else {
|
||||
*language_country = NULL;
|
||||
*language_country = nullptr;
|
||||
}
|
||||
}
|
||||
if (language_variant) {
|
||||
@ -338,7 +340,7 @@ void BLT_lang_locale_explode(const char *locale,
|
||||
*language_variant = m1 ? BLI_strdupcat(_t, m2) : BLI_strdup(locale);
|
||||
}
|
||||
else {
|
||||
*language_variant = NULL;
|
||||
*language_variant = nullptr;
|
||||
}
|
||||
}
|
||||
if (_t && !language) {
|
@ -46,9 +46,9 @@ const char *BLT_pgettext(const char *msgctxt, const char *msgid)
|
||||
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!
|
||||
*/
|
||||
/* 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);
|
@ -9,7 +9,7 @@ set(INC
|
||||
)
|
||||
|
||||
set(SRC
|
||||
msgfmt.c
|
||||
msgfmt.cc
|
||||
)
|
||||
|
||||
set(LIB
|
||||
|
@ -31,32 +31,32 @@
|
||||
|
||||
/* Stupid stub necessary because some BLI files includes winstuff.h, which uses G a bit... */
|
||||
#ifdef WIN32
|
||||
typedef struct Global {
|
||||
struct Global {
|
||||
void *dummy;
|
||||
} Global;
|
||||
};
|
||||
|
||||
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) */
|
||||
/* 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 {
|
||||
enum eSectionType {
|
||||
SECTION_NONE = 0,
|
||||
SECTION_CTX = 1,
|
||||
SECTION_ID = 2,
|
||||
SECTION_STR = 3,
|
||||
} eSectionType;
|
||||
};
|
||||
|
||||
typedef struct Message {
|
||||
struct Message {
|
||||
DynStr *ctxt;
|
||||
DynStr *id;
|
||||
DynStr *str;
|
||||
|
||||
bool is_fuzzy;
|
||||
} Message;
|
||||
};
|
||||
|
||||
static char *trim(char *str)
|
||||
{
|
||||
@ -131,11 +131,11 @@ static char **get_keys_sorted(GHash *messages, const uint32_t num_keys)
|
||||
{
|
||||
GHashIterator iter;
|
||||
|
||||
char **keys = MEM_mallocN(sizeof(*keys) * num_keys, __func__);
|
||||
char **keys = static_cast<char **>(MEM_mallocN(sizeof(*keys) * num_keys, __func__));
|
||||
char **k = keys;
|
||||
|
||||
GHASH_ITER (iter, messages) {
|
||||
*k = BLI_ghashIterator_getKey(&iter);
|
||||
*k = static_cast<char *>(BLI_ghashIterator_getKey(&iter));
|
||||
k++;
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ BLI_INLINE size_t uint32_to_bytes(const int value, char *bytes)
|
||||
|
||||
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... */
|
||||
/* Note that we also perform replacing of our NULLSEP placeholder by real nullptr char... */
|
||||
size_t i;
|
||||
for (i = 0; i < size; i++, msg++, bytes++) {
|
||||
*bytes = (*msg == NULLSEP_CHR) ? '\0' : *msg;
|
||||
@ -174,19 +174,19 @@ static char *generate(GHash *messages, size_t *r_output_size)
|
||||
|
||||
/* Get list of sorted keys. */
|
||||
char **keys = get_keys_sorted(messages, num_keys);
|
||||
char **vals = MEM_mallocN(sizeof(*vals) * num_keys, __func__);
|
||||
char **vals = static_cast<char **>(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__);
|
||||
Offset *offsets = static_cast<Offset *>(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]);
|
||||
vals[i] = static_cast<char *>(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. */
|
||||
* Each string is nullptr terminated; the nullptr 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;
|
||||
@ -207,7 +207,7 @@ static char *generate(GHash *messages, size_t *r_output_size)
|
||||
|
||||
/* Final buffer representing the binary MO file. */
|
||||
*r_output_size = valstart + tot_vals_len;
|
||||
char *output = MEM_mallocN(*r_output_size, __func__);
|
||||
char *output = static_cast<char *>(MEM_mallocN(*r_output_size, __func__));
|
||||
char *h = output;
|
||||
char *ik = output + idx_keystart;
|
||||
char *iv = output + idx_valstart;
|
||||
@ -258,8 +258,10 @@ static void add(GHash *messages, MemArena *memarena, const Message *msg)
|
||||
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));
|
||||
char *msgkey = static_cast<char *>(
|
||||
BLI_memarena_alloc(memarena, sizeof(*msgkey) * (msgkey_len + 1)));
|
||||
char *msgstr = static_cast<char *>(
|
||||
BLI_memarena_alloc(memarena, sizeof(*msgstr) * (msgstr_len + 1)));
|
||||
|
||||
if (msgctxt_len != 0) {
|
||||
BLI_dynstr_get_cstring_ex(msg->ctxt, msgkey);
|
||||
@ -303,19 +305,18 @@ static int make(const char *input_file_name, const char *output_file_name)
|
||||
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,
|
||||
};
|
||||
Message msg{};
|
||||
msg.ctxt = BLI_dynstr_new_memarena();
|
||||
msg.id = BLI_dynstr_new_memarena();
|
||||
msg.str = BLI_dynstr_new_memarena();
|
||||
msg.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;
|
||||
char *l = static_cast<char *>(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) {
|
||||
@ -325,7 +326,7 @@ static int make(const char *input_file_name, const char *output_file_name)
|
||||
section = SECTION_NONE;
|
||||
}
|
||||
/* Record a fuzzy mark. */
|
||||
if (l[1] == ',' && strstr(l, "fuzzy") != NULL) {
|
||||
if (l[1] == ',' && strstr(l, "fuzzy") != nullptr) {
|
||||
msg.is_fuzzy = true;
|
||||
}
|
||||
/* Skip comments */
|
||||
@ -374,7 +375,7 @@ static int make(const char *input_file_name, const char *output_file_name)
|
||||
printf("plural without msgid_plural on %s:%d\n", input_file_name, lno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((l = strchr(l, ']')) == NULL) {
|
||||
if ((l = strchr(l, ']')) == nullptr) {
|
||||
printf("Syntax error on %s:%d\n", input_file_name, lno);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -433,7 +434,7 @@ static int make(const char *input_file_name, const char *output_file_name)
|
||||
fclose(fp);
|
||||
|
||||
MEM_freeN(output);
|
||||
BLI_ghash_free(messages, NULL, NULL);
|
||||
BLI_ghash_free(messages, nullptr, nullptr);
|
||||
BLI_memarena_free(msgs_memarena);
|
||||
|
||||
return EXIT_SUCCESS;
|
Loading…
Reference in New Issue
Block a user