Skip to content

Commit

Permalink
Switch to using po/mo files for translations
Browse files Browse the repository at this point in the history
As a test for now.  Would need to make sure that the speed is
acceptable.

Doing this because it makes it easier to work on the UI without having
to update the translation strings list each time I add a new label.

I am using a small custom made mo reader since I don't want to add a
dependency to gettext, and also I prefer to bundle all the translations
directly in the binary.
  • Loading branch information
guillaumechereau committed Jul 18, 2024
1 parent 94a0b5d commit 29f386d
Show file tree
Hide file tree
Showing 46 changed files with 1,322 additions and 1,018 deletions.
Binary file added data/locale/fr.mo
Binary file not shown.
594 changes: 594 additions & 0 deletions po/fr.po

Large diffs are not rendered by default.

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.
int help; // Help text string id.
const char *help;
int flags;
const char *default_shortcut;
char shortcut[8]; // Can be changed at runtime.
Expand Down
1 change: 1 addition & 0 deletions src/assets.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static asset_t ASSETS[] = {
#include "assets/fonts.inl"
#include "assets/icons.inl"
#include "assets/images.inl"
#include "assets/locale.inl"
#include "assets/other.inl"
#include "assets/palettes.inl"
#include "assets/progs.inl"
Expand Down
319 changes: 319 additions & 0 deletions src/assets/locale.inl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/filters/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int gui(filter_t *filter_)
goxel_apply_color_filter(apply_values, filter);
}

if (gui_button(_(RESET), -1, 0)) {
if (gui_button(_("Reset"), -1, 0)) {
volume_set(layer->volume, filter->original);
filter->hue = 0;
filter->lightness = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/formats/gltf.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,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_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
4 changes: 2 additions & 2 deletions src/formats/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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(_(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 @@ -61,7 +61,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
2 changes: 1 addition & 1 deletion src/formats/wavefront.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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_CONVENTION));
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
22 changes: 11 additions & 11 deletions src/goxel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ static void a_cut_as_new_layer(void)
}

ACTION_REGISTER(ACTION_cut_as_new_layer,
.help = STR_ACTION_CUT_AS_NEW_LAYER,
.help = N_("Cuts the selected area into a new layer"),
.cfunc = a_cut_as_new_layer,
.flags = ACTION_TOUCH_IMAGE,
)
Expand Down Expand Up @@ -1600,7 +1600,7 @@ static void a_fill_selection_box(void)
}

ACTION_REGISTER(ACTION_fill_selection_box,
.help = STR_ACTION_FILL_SELECTION_BOX_HELP,
.help = N_("Fills the selected box with the current color"),
.cfunc = a_fill_selection_box,
.flags = ACTION_TOUCH_IMAGE,
)
Expand All @@ -1615,7 +1615,7 @@ static void a_paint_selection(void)
}

ACTION_REGISTER(ACTION_paint_selection,
.help = STR_ACTION_PAINT_SELECTION_HELP,
.help = N_("Fills the selected voxels with the current color"),
.cfunc = a_paint_selection,
.flags = ACTION_TOUCH_IMAGE,
)
Expand All @@ -1640,7 +1640,7 @@ static void a_add_selection(void)
}

ACTION_REGISTER(ACTION_add_selection,
.help = STR_ACTION_ADD_SELECTION_HELP,
.help = N_("Adds selected area to the mask"),
.cfunc = a_add_selection,
)

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

ACTION_REGISTER(ACTION_sub_selection,
.help = STR_ACTION_SUB_SELECTION_HELP,
.help = N_("Subtracts selected area from the mask"),
.cfunc = a_sub_selection,
)

Expand Down Expand Up @@ -1783,7 +1783,7 @@ ACTION_REGISTER(ACTION_view_front,
)

ACTION_REGISTER(ACTION_view_toggle_ortho,
.help = STR_ACTION_VIEW_TOGGLE_ORTHO_HELP,
.help = N_("Switches the projection (perspective/orthographic)"),
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = a_view_toggle_ortho,
.default_shortcut = "5",
Expand Down Expand Up @@ -1841,7 +1841,7 @@ static void a_reset(void)
}

ACTION_REGISTER(ACTION_reset,
.help = STR_ACTION_RESET_HELP,
.help = N_("Creates a new image (discards the current one)"),
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = a_reset,
.default_shortcut = "Ctrl N"
Expand Down Expand Up @@ -1879,7 +1879,7 @@ static void toggle_mode(void)
}

ACTION_REGISTER(ACTION_toggle_mode,
.help = STR_ACTION_TOGGLE_MODE_HELP,
.help = N_("Switches the mode (add/subtract/paint)"),
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc = toggle_mode,
)
Expand All @@ -1891,7 +1891,7 @@ static void a_set_mode(void *data)
}

ACTION_REGISTER(ACTION_set_mode_add,
.help = STR_ACTION_SET_MODE_ADD_HELP,
.help = N_("Adds to the voxels"),
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_set_mode,
.data = (int[]){MODE_OVER},
Expand All @@ -1900,7 +1900,7 @@ ACTION_REGISTER(ACTION_set_mode_add,
)

ACTION_REGISTER(ACTION_set_mode_sub,
.help = STR_ACTION_SET_MODE_SUB_HELP,
.help = N_("Subtract to the voxels"),
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_set_mode,
.data = (int[]){MODE_SUB},
Expand All @@ -1909,7 +1909,7 @@ ACTION_REGISTER(ACTION_set_mode_sub,
)

ACTION_REGISTER(ACTION_set_mode_paint,
.help = STR_ACTION_SET_MODE_PAINT_HELP,
.help = N_("Paints the voxels"),
.flags = ACTION_CAN_EDIT_SHORTCUT,
.cfunc_data = a_set_mode,
.data = (int[]){MODE_PAINT},
Expand Down
4 changes: 2 additions & 2 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,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
31 changes: 15 additions & 16 deletions src/gui/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,31 @@ enum {
};

static struct {
int name;
const char *name;
int icon;
void (*fn)(void);
bool detached;
} PANELS[] = {
[PANEL_TOOLS] = {STR_TOOLS, ICON_TOOLS, gui_tools_panel},
[PANEL_PALETTE] = {STR_PALETTE, ICON_PALETTE, gui_palette_panel},
[PANEL_EDIT] = {STR_EDIT, ICON_HAMMER, gui_edit_panel},
[PANEL_LAYERS] = {STR_LAYERS, ICON_LAYERS, gui_layers_panel},
[PANEL_SNAP] = {STR_SNAP, ICON_SNAP, gui_snap_panel},
[PANEL_SYMMETRY] = {STR_SYMMETRY, ICON_SYMMETRY, gui_symmetry_panel},
[PANEL_VIEW] = {STR_VIEW, ICON_VIEW, gui_view_panel},
[PANEL_MATERIAL] = {STR_MATERIALS, ICON_MATERIAL, gui_material_panel},
[PANEL_LIGHT] = {STR_LIGHT, ICON_LIGHT, gui_light_panel},
[PANEL_CAMERAS] = {STR_CAMERAS, ICON_CAMERA, gui_cameras_panel},
[PANEL_IMAGE] = {STR_IMAGE, ICON_IMAGE, gui_image_panel},
[PANEL_TOOLS] = {N_("Tools"), ICON_TOOLS, gui_tools_panel},
[PANEL_PALETTE] = {N_("Palette"), ICON_PALETTE, gui_palette_panel},
[PANEL_EDIT] = {N_("Edit"), ICON_HAMMER, gui_edit_panel},
[PANEL_LAYERS] = {N_("Layers"), ICON_LAYERS, gui_layers_panel},
[PANEL_SNAP] = {N_("Snap"), ICON_SNAP, gui_snap_panel},
[PANEL_SYMMETRY] = {N_("Symmetry"), ICON_SYMMETRY, gui_symmetry_panel},
[PANEL_VIEW] = {N_("View"), ICON_VIEW, gui_view_panel},
[PANEL_MATERIAL] = {N_("Materials"), ICON_MATERIAL, gui_material_panel},
[PANEL_LIGHT] = {N_("Light"), ICON_LIGHT, gui_light_panel},
[PANEL_CAMERAS] = {N_("Cameras"), ICON_CAMERA, gui_cameras_panel},
[PANEL_IMAGE] = {N_("Image"), ICON_IMAGE, gui_image_panel},
#if YOCTO
[PANEL_RENDER] = {STR_RENDER, ICON_RENDER, gui_render_panel},
[PANEL_RENDER] = {N_("Render"), ICON_RENDER, gui_render_panel},
#endif
[PANEL_EXPORT] = {STR_EXPORT, ICON_EXPORT, gui_export_panel},
[PANEL_EXPORT] = {N_("Export"), ICON_EXPORT, gui_export_panel},
#if DEBUG
[PANEL_DEBUG] = {STR_DEBUG, ICON_DEBUG, gui_debug_panel},
[PANEL_DEBUG] = {N_("Debug"), ICON_DEBUG, gui_debug_panel},
#endif
};


static void on_click(void) {
if (DEFINED(GUI_SOUND))
sound_play("click", 1.0, 1.0);
Expand Down
16 changes: 8 additions & 8 deletions src/gui/cameras_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ void gui_cameras_panel(void)
cam = goxel.image->active_camera;

if (gui_section_begin(cam->name, GUI_SECTION_COLLAPSABLE)) {
gui_input_float(_(DISTANCE), &cam->dist, 10.0, 0, 0, NULL);
gui_checkbox(_(ORTHOGRAPHIC), &cam->ortho, NULL);
gui_input_float(_("Distance"), &cam->dist, 10.0, 0, 0, NULL);
gui_checkbox(_("Orthographic"), &cam->ortho, NULL);
gui_group_begin(NULL);
gui_row_begin(2);
gui_action_button(ACTION_view_left, _(LEFT), 1.0);
gui_action_button(ACTION_view_right, _(RIGHT), 1.0);
gui_action_button(ACTION_view_left, _("Left"), 1.0);
gui_action_button(ACTION_view_right, _("Right"), 1.0);
gui_row_end();
gui_row_begin(2);
gui_action_button(ACTION_view_front, _(FRONT), 1.0);
gui_action_button(ACTION_view_top, _(TOP), 1.0);
gui_action_button(ACTION_view_front, _("Front"), 1.0);
gui_action_button(ACTION_view_top, _("Top"), 1.0);
gui_row_end();
gui_action_button(ACTION_view_default, _(RESET), 1.0);
gui_action_button(ACTION_view_default, _("Reset"), 1.0);
gui_group_end();

// Allow to edit euler angles (Should this be a generic widget?)
Expand All @@ -75,7 +75,7 @@ void gui_cameras_panel(void)
pitch = round(eul[0] * DR2D);
if (pitch < 0) pitch += 360;
v = pitch;
snprintf(buf, sizeof(buf), "%s: X", _(ANGLE));
snprintf(buf, sizeof(buf), "%s: X", _("Angle"));
if (gui_input_float(buf, &v, 1, -90, 90, "%.0f")) {
v = (v - pitch) * DD2R;
camera_turntable(cam, 0, v);
Expand Down
12 changes: 6 additions & 6 deletions src/gui/edit_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ void gui_edit_panel(void)

gui_group_begin(NULL);
gui_enabled_begin(!box_is_null(img->selection_box));
gui_action_button(ACTION_fill_selection_box, _(FILL), 1.0);
gui_action_button(ACTION_fill_selection_box, _("Fill"), 1.0);
gui_group_end();
gui_enabled_end();

gui_group_begin(NULL);
gui_enabled_begin(!volume_is_empty(goxel.image->selection_mask));
gui_action_button(ACTION_layer_clear, _(CLEAR), 1.0);
gui_action_button(ACTION_paint_selection, _(PAINT), 1.0);
gui_action_button(ACTION_cut_as_new_layer, "Cut as new layer", 1.0);
gui_action_button(ACTION_layer_clear, _("Clear"), 1.0);
gui_action_button(ACTION_paint_selection, _("Paint"), 1.0);
gui_action_button(ACTION_cut_as_new_layer, _("Cut as new layer"), 1.0);
gui_enabled_end();
gui_group_end();

gui_group_begin(NULL);
gui_enabled_begin(!volume_is_empty(goxel.image->selection_mask));
gui_action_button(ACTION_copy, _(COPY), 1.0);
gui_action_button(ACTION_copy, _("Copy"), 1.0);
gui_enabled_end();
gui_enabled_begin(!volume_is_empty(goxel.clipboard.volume));
gui_action_button(ACTION_paste, _(PASTE), 1.0);
gui_action_button(ACTION_paste, _("Paste"), 1.0);
gui_enabled_end();
gui_group_end();
}
4 changes: 2 additions & 2 deletions src/gui/export_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void on_format(void *user, file_format_t *f)
void gui_export_panel(void)
{
char label[128];
gui_text(_(FORMAT));
gui_text(_("Format"));
if (!g_current) g_current = file_formats; // First one.

make_label(g_current, label, sizeof(label));
Expand All @@ -70,7 +70,7 @@ void gui_export_panel(void)

if (g_current->export_gui)
g_current->export_gui(g_current);
if (gui_button(_(EXPORT), 1, 0))
if (gui_button(_("Export"), 1, 0))
goxel_export_to_file(NULL, g_current->name);
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/image_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ void gui_image_panel(void)
image_t *image = goxel.image;
float (*box)[4][4] = &image->box;
gui_bbox(*box);
gui_action_button(ACTION_img_auto_resize, _(FIT_TO_CONTENT), -1);
gui_action_button(ACTION_img_auto_resize, _("Fit to Content"), -1);
}

24 changes: 12 additions & 12 deletions src/gui/layers_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ static void layers_context_menu(void)
bool bounded;
char buf[256];

gui_action_button(ACTION_img_duplicate_layer, _(DUPLICATE), 1);
gui_action_button(ACTION_img_clone_layer, _(CLONE), 1);
gui_action_button(ACTION_img_merge_layer_down, _(MERGE_DOWN), 1);
gui_action_button(ACTION_img_merge_visible_layers, _(MERGE_VISIBLE), 1);
gui_action_button(ACTION_img_duplicate_layer, _("Duplicate"), 1);
gui_action_button(ACTION_img_clone_layer, _("Clone"), 1);
gui_action_button(ACTION_img_merge_layer_down, _("Merge Down"), 1);
gui_action_button(ACTION_img_merge_visible_layers, _("Merge Visible"), 1);

layer = goxel.image->active_layer;
bounded = !box_is_null(layer->box);

if (bounded && gui_button(_(CROP), 1, 0)) {
if (bounded && gui_button(_("Crop"), 1, 0)) {
volume_crop(layer->volume, layer->box);
}
if (!box_is_null(goxel.image->box)) {
snprintf(buf, sizeof(buf), "%s: %s", _(CROP), _(IMAGE));
snprintf(buf, sizeof(buf), "%s: %s", _("Crop"), _("Image"));
if (gui_button(buf, 1, 0))
volume_crop(layer->volume, goxel.image->box);
}
if (layer->shape) {
snprintf(buf, sizeof(buf), "▶ %s", _(VOLUME));
snprintf(buf, sizeof(buf), "▶ %s", _("Volume"));
gui_action_button(ACTION_img_unclone_layer, buf, 1);
}

snprintf(buf, sizeof(buf), "%s: %s", _(ADD), _(SHAPE));
snprintf(buf, sizeof(buf), "%s: %s", _("Add"), _("Shape"));
if (gui_action_button(ACTION_img_new_shape_layer, buf, 1)) {
action_exec2(ACTION_tool_set_move);
}
Expand Down Expand Up @@ -135,15 +135,15 @@ void gui_layers_panel(void)

if (layer->base_id) {
gui_group_begin(NULL);
gui_action_button(ACTION_img_unclone_layer, _(UNLINK), 1);
gui_action_button(ACTION_img_unclone_layer, _("Unlink"), 1);
gui_action_button(ACTION_img_select_parent_layer, "Select parent", 1);
gui_group_end();
}
if (layer->image) {
snprintf(buf, sizeof(buf), "-> %s", _(VOLUME));
snprintf(buf, sizeof(buf), "-> %s", _("Volume"));
gui_action_button(ACTION_img_image_layer_to_volume, buf, 1);
}
if (!layer->shape && gui_checkbox(_(BOUNDED), &bounded, NULL)) {
if (!layer->shape && gui_checkbox(_("Bounded"), &bounded, NULL)) {
if (bounded) {
volume_get_bbox(layer->volume, bbox, true);
if (bbox[0][0] > bbox[1][0]) memset(bbox, 0, sizeof(bbox));
Expand All @@ -160,7 +160,7 @@ void gui_layers_panel(void)
gui_color("##color", layer->color);
}

gui_text(_(MATERIAL));
gui_text(_("Material"));
if (gui_combo_begin("##material",
layer->material ? layer->material->name : NULL)) {
DL_FOREACH(goxel.image->materials, material) {
Expand Down
Loading

0 comments on commit 29f386d

Please sign in to comment.