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-07-09 18:25:35 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-07-09 18:25:35 +0400
commit0dafa97ea3f6d9662299579e5be1875cd28baaae (patch)
tree149bb7181a73dabc619d546a4f153ad6ed3050ad /source/blender/editors/interface/interface_ops.c
parentfacb1512c097189e50808f6aca7c9f0b0280d2dc (diff)
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator. It also adds a few getters (to get RNA i18n context, and current language iso code). Finally, it adds to C operators needed for the py ui_translation addon: *UI_OT_edittranslation_init, which gathers requested data and launch the py operator. *UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files). For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c165
1 files changed, 161 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 1c3b642b63b..b76907bc3ba 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -43,6 +43,9 @@
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
+#include "BLF_api.h"
+#include "BLF_translation.h"
+
#include "BKE_context.h"
#include "BKE_screen.h"
#include "BKE_global.h"
@@ -732,8 +735,6 @@ void UI_editsource_active_but_test(uiBut *but)
BLI_ghash_insert(ui_editsource_info->hash, but, but_store);
}
-/* editsource operator component */
-
static int editsource_text_edit(bContext *C, wmOperator *op,
char filepath[FILE_MAX], int line)
{
@@ -843,16 +844,170 @@ static int editsource_exec(bContext *C, wmOperator *op)
static void UI_OT_editsource(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Reports to Text Block";
+ ot->name = "Edit Source";
ot->idname = "UI_OT_editsource";
- ot->description = "Edit source code for a button";
+ ot->description = "Edit UI source code of the active button";
/* callbacks */
ot->exec = editsource_exec;
}
+/* ------------------------------------------------------------------------- */
+/* EditTranslation utility funcs and operator,
+ * Note: this includes utility functions and button matching checks.
+ * this only works in conjunction with a py operator! */
+
+void edittranslation_find_po_file(const char *root, const char *uilng, char *path, const size_t maxlen)
+{
+ char t[32]; /* Should be more than enough! */
+ /* First, full lang code. */
+ sprintf(t, "%s.po", uilng);
+ BLI_join_dirfile(path, maxlen, root, uilng);
+ BLI_join_dirfile(path, maxlen, path, t);
+ if (BLI_is_file(path))
+ return;
+ /* Now try without the second iso code part (_ES in es_ES). */
+ strncpy(t, uilng, 2);
+ strcpy(t + 2, uilng + 5); /* Because of some codes like sr_SR@latin... */
+ BLI_join_dirfile(path, maxlen, root, t);
+ sprintf(t, "%s.po", t);
+ BLI_join_dirfile(path, maxlen, path, t);
+ if (BLI_is_file(path))
+ return;
+ path[0] = '\0';
+}
+
+static int edittranslation_exec(bContext *C, wmOperator *op)
+{
+ uiBut *but = uiContextActiveButton(C);
+ int ret = OPERATOR_CANCELLED;
+
+ if (but) {
+ PointerRNA ptr;
+ char popath[FILE_MAX];
+ const char *root = U.i18ndir;
+ const char *uilng = BLF_lang_get();
+
+ const int bufs_nbr = 10;
+ uiStringInfo but_label = {BUT_GET_LABEL, NULL};
+ uiStringInfo rna_label = {BUT_GET_RNA_LABEL, NULL};
+ uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, NULL};
+ uiStringInfo but_tip = {BUT_GET_TIP, NULL};
+ uiStringInfo rna_tip = {BUT_GET_RNA_TIP, NULL};
+ uiStringInfo enum_tip = {BUT_GET_RNAENUM_TIP, NULL};
+ uiStringInfo rna_struct = {BUT_GET_RNASTRUCT_IDENTIFIER, NULL};
+ uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, NULL};
+ uiStringInfo rna_enum = {BUT_GET_RNAENUM_IDENTIFIER, NULL};
+ uiStringInfo rna_ctxt = {BUT_GET_RNA_LABEL_CONTEXT, NULL};
+
+ if (!BLI_is_dir(root)) {
+ BKE_report(op->reports, RPT_ERROR, "Please set your User Preferences' \"Translation Branches "
+ "Directory\" path to a valid directory.");
+ return OPERATOR_CANCELLED;
+ }
+ if (!WM_operatortype_find(EDTSRC_I18N_OP_NAME, 0)) {
+ BKE_reportf(op->reports, RPT_ERROR, "Could not find operator \"%s\"! Please enable ui_translate addon "
+ "in the User Preferences.", EDTSRC_I18N_OP_NAME);
+ return OPERATOR_CANCELLED;
+ }
+ /* 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);
+ if (popath[0] == '\0') {
+ BKE_reportf(op->reports, RPT_ERROR, "No valid po found for language '%s' under %s.", uilng, root);
+ return OPERATOR_CANCELLED;
+ }
+
+ uiButGetStrInfo(C, but, bufs_nbr, &but_label, &rna_label, &enum_label, &but_tip, &rna_tip, &enum_tip,
+ &rna_struct, &rna_prop, &rna_enum, &rna_ctxt);
+
+ WM_operator_properties_create(&ptr, EDTSRC_I18N_OP_NAME);
+ RNA_string_set(&ptr, "lang", uilng);
+ RNA_string_set(&ptr, "po_file", popath);
+ RNA_string_set(&ptr, "but_label", but_label.strinfo);
+ RNA_string_set(&ptr, "rna_label", rna_label.strinfo);
+ RNA_string_set(&ptr, "enum_label", enum_label.strinfo);
+ RNA_string_set(&ptr, "but_tip", but_tip.strinfo);
+ RNA_string_set(&ptr, "rna_tip", rna_tip.strinfo);
+ RNA_string_set(&ptr, "enum_tip", enum_tip.strinfo);
+ RNA_string_set(&ptr, "rna_struct", rna_struct.strinfo);
+ RNA_string_set(&ptr, "rna_prop", rna_prop.strinfo);
+ RNA_string_set(&ptr, "rna_enum", rna_enum.strinfo);
+ RNA_string_set(&ptr, "rna_ctxt", rna_ctxt.strinfo);
+ ret = WM_operator_name_call(C, EDTSRC_I18N_OP_NAME, WM_OP_INVOKE_DEFAULT, &ptr);
+
+ /* Clean up */
+ if (but_label.strinfo)
+ MEM_freeN(but_label.strinfo);
+ if (rna_label.strinfo)
+ MEM_freeN(rna_label.strinfo);
+ if (enum_label.strinfo)
+ MEM_freeN(enum_label.strinfo);
+ if (but_tip.strinfo)
+ MEM_freeN(but_tip.strinfo);
+ if (rna_tip.strinfo)
+ MEM_freeN(rna_tip.strinfo);
+ if (enum_tip.strinfo)
+ MEM_freeN(enum_tip.strinfo);
+ if (rna_struct.strinfo)
+ MEM_freeN(rna_struct.strinfo);
+ if (rna_prop.strinfo)
+ MEM_freeN(rna_prop.strinfo);
+ if (rna_enum.strinfo)
+ MEM_freeN(rna_enum.strinfo);
+ if (rna_ctxt.strinfo)
+ MEM_freeN(rna_ctxt.strinfo);
+
+ return ret;
+ }
+ else {
+ BKE_report(op->reports, RPT_ERROR, "Active button not found");
+ return OPERATOR_CANCELLED;
+ }
+}
+
+#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 */
+ ot->name = "Edit Translation";
+ ot->idname = "UI_OT_edittranslation_init";
+ ot->description = "Edit i18n in current language for the active button";
+
+ /* callbacks */
+ ot->exec = edittranslation_exec;
+/* ot->poll = edittranslation_poll;*/
+}
+
#endif /* WITH_PYTHON */
+static int reloadtranslation_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
+ BLF_lang_init();
+ BLF_cache_clear();
+ BLF_lang_set(NULL);
+ UI_reinit_font();
+ return OPERATOR_FINISHED;
+}
+
+static void UI_OT_reloadtranslation(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Reload Translation";
+ ot->idname = "UI_OT_reloadtranslation";
+ ot->description = "Force a full reload of UI translation";
+
+ /* callbacks */
+ ot->exec = reloadtranslation_exec;
+}
+
/* ********************************************************* */
/* Registration */
@@ -867,6 +1022,8 @@ void UI_buttons_operatortypes(void)
#ifdef WITH_PYTHON
WM_operatortype_append(UI_OT_editsource);
+ WM_operatortype_append(UI_OT_edittranslation_init);
#endif
+ WM_operatortype_append(UI_OT_reloadtranslation);
}