Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localisation for v1.00 #549

Open
piponazo opened this issue Nov 16, 2018 · 6 comments
Open

Localisation for v1.00 #549

piponazo opened this issue Nov 16, 2018 · 6 comments
Labels
L10n Translation languages umbrella Collection of other issues
Milestone

Comments

@piponazo
Copy link
Collaborator

In #527 and #537 we discussed a lot about localisation stuff just before the 0.27 release.

The only missing point (that was not critical for 0.27) was to provide some API function to change the language at run-time. While this is trivial in other translation systems like the one provided by Qt, it seems a bit more challenging with gettext and libintl. The recommended way according to the gettext documentation is to set the environment variable LANGUAGE to the desired value in the application code.

This piece of code seems to work:

#include <libintl.h>
#include <locale.h>

#define _(STRING) gettext(STRING)

#include <cstdio>
#include <cstdlib>

int main()
{
  // Setting the i18n environment
  setlocale (LC_ALL, "");
  bindtextdomain ("hello", "/usr/share/locale/");
  textdomain ("hello");

  // Example of i18n usage
  printf(_("Hello World\n"));

  setenv("LANGUAGE", "es_ES", 1);

  printf(_("Hello World\n"));

  return EXIT_SUCCESS;
}

--------
13:30 $ ./app 
Hello World
Hola Mundo

The idea would be to have something like Exiv2::loadLocalisation() maybe with a string argument to indicate the language and being able to switch languages at run time.

@piponazo piponazo added good first issue L10n Translation languages labels Nov 16, 2018
@piponazo piponazo added this to the v0.28 milestone Nov 16, 2018
@phako
Copy link
Contributor

phako commented Oct 7, 2019

Is there any valid use-case for changing localisation during runtime?

@D4N
Copy link
Member

D4N commented Oct 7, 2019 via email

@phako
Copy link
Contributor

phako commented Oct 7, 2019

There is no need to recompile the application, under a normal desktop, LANGUAGE or the corresponding LC_* are set by the DE, you just need to restart the application to change to the "new" language.

i.e.

        setlocale (LC_ALL, "");
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

is usually all you need, together with a helper header that contains the definitions for _() and, ideally, N_() for static strings.

@D4N
Copy link
Member

D4N commented Oct 7, 2019 via email

@clanmills clanmills modified the milestones: old-master, v1.00 Apr 13, 2021
@clanmills
Copy link
Collaborator

Yes. I've got this on the list for test issues for v1.00 #1550.

@clanmills clanmills changed the title Localisation for v0.28 Localisation for v1.00 Apr 13, 2021
@clanmills clanmills added the umbrella Collection of other issues label Apr 13, 2021
@jim-easterbrook
Copy link
Contributor

I've been having some fun localising my Python interface to libexiv2 (v0.26 to 0.27.5) and it seems here is as good a place as any to report my findings. In most cases I use copies of the .mo files, installed in the Python packages directory. The trick to getting this to work was to call Exiv2::exvGettext to initialise it before calling bindtextdomain to set my own path.

The next problem was when using the system installed .mo files (in /usr/share/locale in my case). libexiv2's initialisation computes localeDir relative to the executable path, which is fine for the exiv2 tool but less useful when libexiv2 is used by executables in a different directory. I overcame this by calling bindtextdomain without a dirname to get the system default, then setting it as above.

Could I suggest that libexiv2's initialisation tries the system default path (on those systems that have one) as well as the one computed from the executable path and chooses whichever actually has the .mo files.

@kevinbackhouse kevinbackhouse modified the milestones: v0.28.0, Backlog Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L10n Translation languages umbrella Collection of other issues
Projects
None yet
Development

No branches or pull requests

6 participants