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:
authorBastien Montagne <montagne29@wanadoo.fr>2012-09-27 18:38:20 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-09-27 18:38:20 +0400
commit3a788ffd66e16fd1d80e5b5a09810f50915c6bd6 (patch)
tree962c5023fac5bc4fe6c6e469d69d76a974b23a45 /source/blender/editors/interface/interface_ops.c
parentc1abde5935eef790420308ba740ea45d14904708 (diff)
Fix/enhancement of "locale to po file name" code. Now should handle nicely locales like "gez_ER@abegede", and never read uilng string beyond its end!
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index ded5887f7f2..1ee06b1ff64 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -915,20 +915,41 @@ static void UI_OT_editsource(wmOperatorType *ot)
static void edittranslation_find_po_file(const char *root, const char *uilng, char *path, const size_t maxlen)
{
char tstr[32]; /* Should be more than enough! */
+
/* First, full lang code. */
BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng);
BLI_join_dirfile(path, maxlen, root, uilng);
BLI_join_dirfile(path, maxlen, path, tstr);
if (BLI_is_file(path))
return;
+
/* Now try without the second iso code part (_ES in es_ES). */
- strncpy(tstr, uilng, 2);
- BLI_strncpy(tstr + 2, uilng + 5, sizeof(tstr) - 2); /* Because of some codes like sr_SR@latin... */
- BLI_join_dirfile(path, maxlen, root, tstr);
- strcat(tstr, ".po");
- BLI_join_dirfile(path, maxlen, path, tstr);
- if (BLI_is_file(path))
- return;
+ {
+ char *tc = NULL;
+ size_t szt = 0;
+ tstr[0] = '\0';
+
+ tc = strchr(uilng, '_');
+ if (tc) {
+ szt = tc - uilng;
+ if (szt < sizeof(tstr)) /* Paranoid, should always be true! */
+ BLI_strncpy(tstr, uilng, szt + 1); /* +1 for '\0' char! */
+ }
+ if (tstr[0]) {
+ /* Because of some codes like sr_SR@latin... */
+ tc = strchr(uilng, '@');
+ if (tc)
+ BLI_strncpy(tstr + szt, tc, sizeof(tstr) - szt);
+
+ BLI_join_dirfile(path, maxlen, root, tstr);
+ strcat(tstr, ".po");
+ BLI_join_dirfile(path, maxlen, path, tstr);
+ if (BLI_is_file(path))
+ return;
+ }
+ }
+
+ /* Else no po file! */
path[0] = '\0';
}
@@ -967,7 +988,7 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
}
/* Try to find a valid po file for current language... */
edittranslation_find_po_file(root, uilng, popath, FILE_MAX);
- printf("po path: %s\n", popath);
+/* printf("po path: %s\n", popath);*/
if (popath[0] == '\0') {
BKE_reportf(op->reports, RPT_ERROR, "No valid po found for language '%s' under %s.", uilng, root);
return OPERATOR_CANCELLED;
@@ -1021,14 +1042,6 @@ static int edittranslation_exec(bContext *C, wmOperator *op)
}
}
-#if 0
-static int edittranslation_poll(bContext *UNUSED(C))
-{
- /* We need the i18n py addon to be enabled! */
- return WM_operatortype_find(EDTSRC_I18N_OP_NAME, 0) ? TRUE : FALSE;
-}
-#endif
-
static void UI_OT_edittranslation_init(wmOperatorType *ot)
{
/* identifiers */
@@ -1038,7 +1051,6 @@ static void UI_OT_edittranslation_init(wmOperatorType *ot)
/* callbacks */
ot->exec = edittranslation_exec;
-/* ot->poll = edittranslation_poll;*/
}
#endif /* WITH_PYTHON */