Skip to content

Commit

Permalink
Add support for French translations
Browse files Browse the repository at this point in the history
Not totally finished yet.  Later I would like to add more languages as
well.

For now I use a simple array of translations string directly set in a C
file (i18n.h/c) instead of using gettext, so that we don't have to use
any tooling.
  • Loading branch information
guillaumechereau committed Feb 8, 2024
1 parent dd8d242 commit dd0c173
Show file tree
Hide file tree
Showing 37 changed files with 1,212 additions and 263 deletions.
2 changes: 1 addition & 1 deletion src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct action action_t;
struct action {
int idx;
const char *id; // Globally unique id.
const char *help; // Help text.
int help; // Help text string id.
int flags;
const char *default_shortcut;
char shortcut[8]; // Can be changed at runtime.
Expand Down
2 changes: 1 addition & 1 deletion src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum {
X(add_selection),
X(sub_selection),
X(copy),
X(past),
X(paste),
X(view_left),
X(view_right),
X(view_top),
Expand Down
6 changes: 3 additions & 3 deletions src/formats/gltf.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ static int export_as_gltf(const file_format_t *format, const image_t *img,

static void export_gui(file_format_t *format)
{
gui_checkbox("Vertex color", &g_export_options.vertex_color,
"Save colors as a vertex attribute");
gui_input_float("Simplify", &g_export_options.simplify, 0.1,
gui_checkbox(_(VERTEX_COLOR), &g_export_options.vertex_color,
_(SAVE_COLORS_AS_VERTEX_ATTRIBUTE));
gui_input_float(_(SIMPLIFY), &g_export_options.simplify, 0.1,
0, 1, "%.1f");
}

Expand Down
3 changes: 0 additions & 3 deletions src/formats/gox.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,6 @@ static void a_open(void)
}

ACTION_REGISTER(open,
.help = "Open an image",
.cfunc = a_open,
.default_shortcut = "Ctrl O",
)
Expand All @@ -763,7 +762,6 @@ static void a_save_as(void)
}

ACTION_REGISTER(save_as,
.help = "Save the image as",
.cfunc = a_save_as,
)

Expand All @@ -789,7 +787,6 @@ static void a_save(void)
}

ACTION_REGISTER(save,
.help = "Save the image",
.cfunc = a_save,
.default_shortcut = "Ctrl S"
)
Expand Down
4 changes: 2 additions & 2 deletions src/formats/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void export_gui(file_format_t *format)
maxsize /= 2; // Because png export already double it.
goxel.show_export_viewport = true;
gui_group_begin(NULL);
gui_checkbox("Custom size", &goxel.image->export_custom_size, NULL);
gui_checkbox(_(SIZE), &goxel.image->export_custom_size, NULL);
if (!goxel.image->export_custom_size) {
goxel.image->export_width = goxel.gui.viewport[2];
goxel.image->export_height = goxel.gui.viewport[3];
Expand All @@ -57,7 +57,7 @@ static void export_gui(file_format_t *format)
gui_enabled_end();
gui_group_end();

gui_checkbox("Transparent background",
gui_checkbox(_(TRANSPARENT_BACKGROUND),
&goxel.image->export_transparent_background,
NULL);
}
Expand Down
3 changes: 1 addition & 2 deletions src/formats/wavefront.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ int ply_export(const file_format_t *format, const image_t *image,

static void export_gui(file_format_t *format)
{
gui_checkbox("Y-up", &g_export_options.y_up,
"Use Y up instead of Z up");
gui_checkbox(_(Y_UP), &g_export_options.y_up, _(USE_Y_UP_CONVENTION));
}

static void get_file_data(void *ctx, const char *filename, const int is_mtl,
Expand Down
38 changes: 14 additions & 24 deletions src/goxel.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ void goxel_reset(void)
goxel.rend.settings.shadow = 0;

goxel.snap_mask = SNAP_VOLUME | SNAP_IMAGE_BOX;
goxel.mask_mode = MODE_REPLACE;

goxel.pathtracer = (pathtracer_t) {
.num_samples = 512,
Expand Down Expand Up @@ -1331,7 +1332,7 @@ static void a_cut_as_new_layer(void)
}

ACTION_REGISTER(cut_as_new_layer,
.help = "Cut into a new layer",
.help = STR_ACTION_CUT_AS_NEW_LAYER,
.cfunc = a_cut_as_new_layer,
.flags = ACTION_TOUCH_IMAGE,
)
Expand All @@ -1347,7 +1348,6 @@ static void a_reset_selection(void)
}

ACTION_REGISTER(reset_selection,
.help = "Reset the selection",
.cfunc = a_reset_selection,
)

Expand All @@ -1365,7 +1365,7 @@ static void a_fill_selection(void)
}

ACTION_REGISTER(fill_selection,
.help = "Fill the selection with the current paint settings",
.help = STR_ACTION_FILL_SELECTION_HELP,
.cfunc = a_fill_selection,
.flags = ACTION_TOUCH_IMAGE,
)
Expand All @@ -1389,7 +1389,7 @@ static void a_add_selection(void)
}

ACTION_REGISTER(add_selection,
.help = "Add the selection to the current mask",
.help = STR_ACTION_ADD_SELECTION_HELP,
.cfunc = a_add_selection,
)

Expand All @@ -1406,7 +1406,7 @@ static void a_sub_selection(void)
}

ACTION_REGISTER(sub_selection,
.help = "Subtract the selection from the current mask",
.help = STR_ACTION_SUB_SELECTION_HELP,
.cfunc = a_sub_selection,
)

Expand All @@ -1426,7 +1426,7 @@ static void copy_action(void)
}
}

static void past_action(void)
static void paste_action(void)
{
volume_t *volume = goxel.image->active_layer->volume;
volume_t *tmp;
Expand All @@ -1449,15 +1449,13 @@ static void past_action(void)
}

ACTION_REGISTER(copy,
.help = "Copy",
.cfunc = copy_action,
.default_shortcut = "Ctrl C",
.flags = 0,
)

ACTION_REGISTER(past,
.help = "Past",
.cfunc = past_action,
ACTION_REGISTER(paste,
.cfunc = paste_action,
.default_shortcut = "Ctrl V",
.flags = ACTION_TOUCH_IMAGE,
)
Expand Down Expand Up @@ -1494,46 +1492,41 @@ static void a_view_toggle_ortho(void)
}

ACTION_REGISTER(view_left,
.help = "Set camera view to left",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_view_set,
.data = (float[]){90, 90},
.default_shortcut = "Ctrl 3",
)

ACTION_REGISTER(view_right,
.help = "Set camera view to right",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_view_set,
.data = (float[]){-90, 90},
.default_shortcut = "3",
)

ACTION_REGISTER(view_top,
.help = "Set camera view to top",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_view_set,
.data = (float[]){0, 0},
.default_shortcut = "7",
)

ACTION_REGISTER(view_default,
.help = "Set camera view to default",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = a_view_default,
.default_shortcut = "0",
)

ACTION_REGISTER(view_front,
.help = "Set camera view to front",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_view_set,
.data = (float[]){0, 90},
.default_shortcut = "1",
)

ACTION_REGISTER(view_toggle_ortho,
.help = "Toggle between perspective and orthoggraphic view",
.help = STR_ACTION_VIEW_TOGGLE_ORTHO_HELP,
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = a_view_toggle_ortho,
.default_shortcut = "5",
Expand All @@ -1544,7 +1537,6 @@ static void quit(void)
gui_query_quit();
}
ACTION_REGISTER(quit,
.help = "Quit the application",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = quit,
.default_shortcut = "Ctrl Q",
Expand Down Expand Up @@ -1592,7 +1584,7 @@ static void a_reset(void)
}

ACTION_REGISTER(reset,
.help = "New",
.help = STR_ACTION_RESET_HELP,
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = a_reset,
.default_shortcut = "Ctrl N"
Expand All @@ -1602,15 +1594,13 @@ static void undo(void) { image_undo(goxel.image); }
static void redo(void) { image_redo(goxel.image); }

ACTION_REGISTER(undo,
.help = "Undo",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = undo,
.default_shortcut = "Ctrl Z",
.icon = ICON_ARROW_BACK,
)

ACTION_REGISTER(redo,
.help = "Redo",
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = redo,
.default_shortcut = "Ctrl Y",
Expand All @@ -1629,7 +1619,7 @@ static void toggle_mode(void)
}

ACTION_REGISTER(toggle_mode,
.help = "Toggle the tool mode (add, sub, paint)",
.help = STR_ACTION_TOGGLE_MODE_HELP,
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = toggle_mode,
)
Expand All @@ -1641,7 +1631,7 @@ static void a_set_mode(void *data)
}

ACTION_REGISTER(set_mode_add,
.help = "Set tool mode to 'add'",
.help = STR_ACTION_SET_MODE_ADD_HELP,
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_set_mode,
.data = (int[]){MODE_OVER},
Expand All @@ -1650,7 +1640,7 @@ ACTION_REGISTER(set_mode_add,
)

ACTION_REGISTER(set_mode_sub,
.help = "Set tool mode to 'sub'",
.help = STR_ACTION_SET_MODE_SUB_HELP,
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_set_mode,
.data = (int[]){MODE_SUB},
Expand All @@ -1659,7 +1649,7 @@ ACTION_REGISTER(set_mode_sub,
)

ACTION_REGISTER(set_mode_paint,
.help = "Set tool mode to 'sub'",
.help = STR_ACTION_SET_MODE_PAINT_HELP,
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_set_mode,
.data = (int[]){MODE_PAINT},
Expand Down
1 change: 1 addition & 0 deletions src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "gesture.h"
#include "gesture3d.h"
#include "gui.h"
#include "i18n.h"
#include "image.h"
#include "inputs.h"
#include "layer.h"
Expand Down
25 changes: 18 additions & 7 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ static void load_fonts_texture()
const void *data;
int data_size;
ImFontConfig conf;

const ImWchar ranges[] = {
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0x25A0, 0x25FF, // Geometric shapes
Expand All @@ -321,8 +320,20 @@ static void load_fonts_texture()

data = assets_get("asset://data/fonts/DejaVuSans.ttf", &data_size);
assert(data);
io.Fonts->AddFontFromMemoryTTF((void*)data, data_size, 14 * scale,
&conf, ranges);
io.Fonts->AddFontFromMemoryTTF(
(void*)data, data_size, 14 * scale, &conf, ranges);

#if 0
conf.MergeMode = true;
data = assets_get(
"asset://data/fonts/DroidSansFallbackFull.ttf", &data_size);
assert(data);
io.Fonts->AddFontFromMemoryTTF(
(void*)data, data_size, 14 * scale, &conf,
io.Fonts->GetGlyphRangesJapanese());
#endif
io.Fonts->Build();

io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

GLuint tex_id;
Expand Down Expand Up @@ -915,12 +926,12 @@ bool gui_bbox(float box[4][4])
y = round(box[3][1] - box[1][1]);
z = round(box[3][2] - box[2][2]);

gui_group_begin("Origin");
gui_group_begin(_(ORIGIN));
ret |= gui_input_int("x", &x, 0, 0);
ret |= gui_input_int("y", &y, 0, 0);
ret |= gui_input_int("z", &z, 0, 0);
gui_group_end();
gui_group_begin("Size");
gui_group_begin(_(SIZE));
ret |= gui_input_int("w", &w, 0, 0);
ret |= gui_input_int("h", &h, 0, 0);
ret |= gui_input_int("d", &d, 0, 0);
Expand Down Expand Up @@ -963,8 +974,8 @@ bool gui_action_button(int id, const char *label, float size)
assert(action);
ImGui::PushID(action->id);
ret = gui_button(label, size, action->icon);
if (ImGui::IsItemHovered())
goxel_set_help_text(action_get(id, true)->help);
if (ImGui::IsItemHovered() && action->help)
goxel_set_help_text(tr(action->help));
if (ret) {
action_exec(action_get(id, true));
}
Expand Down
Loading

0 comments on commit dd0c173

Please sign in to comment.