From 1905a2b5d15fa118bdbfd46d2987004bbdfa38e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Fri, 18 May 2018 10:34:17 +0200 Subject: [PATCH] i18n: bindtextdomain not hardcoded I've added the locales path to the globals so we can now in the compile time what directory is the translation to use in bindtextdomain Closes https://gitlab.gnome.org/World/fractal/issues/89 --- README.md | 17 +++++++++++++++++ fractal-gtk/build.rs | 17 +++++++++++++++++ fractal-gtk/po/LINGUAS | 1 + fractal-gtk/src/app/mod.rs | 2 +- fractal-gtk/src/globals.rs | 2 ++ meson.build | 3 ++- scripts/cargo.sh | 2 +- 7 files changed, 41 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b5a660a..e8a4a370 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,23 @@ ninja -C _build sudo ninja -C _build install ``` +### Translations + +If you want to add a new language you should update the file +`fractal-gtk/po/LINUGAS` and add the new lang to the list. + +To generate .pot files you should run: + +``` +ninja -C _build fractal-pot +``` + +To generate .po files you should run: + +``` +ninja -C _build fractal-update-po +``` + ### Password Storage Fractal uses Secret Service to store the password so you should have diff --git a/fractal-gtk/build.rs b/fractal-gtk/build.rs index ae6da456..22fa29a0 100644 --- a/fractal-gtk/build.rs +++ b/fractal-gtk/build.rs @@ -1,4 +1,8 @@ use std::process::Command; +use std::env; +use std::fs::File; +use std::path::Path; +use std::io::Write; fn main() { // Compile Gresource @@ -7,4 +11,17 @@ fn main() { .current_dir("res") .status() .unwrap(); + + // Generating build globals + let out_dir = env::var("OUT_DIR").unwrap(); + let localedir = env::var("FRACTAL_LOCALEDIR").unwrap(); + let dest_path = Path::new(&out_dir).join("build_globals.rs"); + let mut f = File::create(&dest_path).unwrap(); + + let globals = format!(" +pub static LOCALEDIR: &'static str = \"{}\"; +", + localedir); + + f.write_all(&globals.into_bytes()[..]).unwrap(); } diff --git a/fractal-gtk/po/LINGUAS b/fractal-gtk/po/LINGUAS index 6fb6fe69..0e3ca9fb 100644 --- a/fractal-gtk/po/LINGUAS +++ b/fractal-gtk/po/LINGUAS @@ -1,3 +1,4 @@ # please keep this list sorted alphabetically # fr +es diff --git a/fractal-gtk/src/app/mod.rs b/fractal-gtk/src/app/mod.rs index 69a0e6d4..cb979de6 100644 --- a/fractal-gtk/src/app/mod.rs +++ b/fractal-gtk/src/app/mod.rs @@ -83,7 +83,7 @@ impl App { // Set up the textdomain for gettext setlocale(LocaleCategory::LcAll, ""); - bindtextdomain("fractal", "./fractal-gtk/po"); + bindtextdomain("fractal", globals::LOCALEDIR); textdomain("fractal"); diff --git a/fractal-gtk/src/globals.rs b/fractal-gtk/src/globals.rs index 4547700c..976afaed 100644 --- a/fractal-gtk/src/globals.rs +++ b/fractal-gtk/src/globals.rs @@ -5,3 +5,5 @@ pub static USERLIST_ICON_SIZE: i32 = 30; pub static MINUTES_TO_SPLIT_MSGS: i64 = 30; pub static APP_ID: &'static str = "org.gnome.Fractal"; + +include!(concat!(env!("OUT_DIR"), "/build_globals.rs")); diff --git a/meson.build b/meson.build index ce9a2d5d..5f69cb72 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ fractal_version_micro = version_array[2].to_int() fractal_prefix = get_option('prefix') fractal_bindir = join_paths(fractal_prefix, get_option('bindir')) +fractal_localedir = join_paths(fractal_prefix, get_option('localedir')) datadir = get_option('datadir') icondir = join_paths(datadir, 'icons') @@ -37,7 +38,7 @@ cargo_release = custom_target('cargo-build', output: ['fractal'], install: true, install_dir: fractal_bindir, - command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@']) + command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@', fractal_localedir]) run_target('release', command: ['scripts/release.sh', meson.project_name() + '-' + fractal_version diff --git a/scripts/cargo.sh b/scripts/cargo.sh index 901d0df6..d28464de 100755 --- a/scripts/cargo.sh +++ b/scripts/cargo.sh @@ -1,6 +1,6 @@ #!/bin/sh -export CARGO_HOME=$1/target/cargo-home +export FRACTAL_LOCALEDIR="$3" if [[ $DEBUG = true ]] then