Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
HOMEBREW_NO_INSTALL_FROM_API: 1
run: brew install libadwaita adwaita-icon-theme gettext webp-pixbuf-loader
- name: Build
run: dotnet build Pinta.sln -c Release
run: dotnet build Pinta.sln -c Release -p:BuildTranslations=true
- name: Test
env:
# Add libraries from homebrew to the search path so they can be loaded by gir.core
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
msystem: ${{matrix.build.mingw_system}}
install: mingw-w64-${{matrix.build.mingw_repo}}-libadwaita mingw-w64-${{matrix.build.mingw_repo}}-webp-pixbuf-loader
- name: Build
run: dotnet build Pinta.sln -c Release -p:MinGWFolder=${{matrix.build.mingw_folder}}
run: dotnet build Pinta.sln -c Release -p:MinGWFolder=${{matrix.build.mingw_folder}} -p:BuildTranslations=true
- name: Test
run: dotnet test Pinta.sln -c Release -p:MinGWFolder=${{matrix.build.mingw_folder}}

Expand Down
18 changes: 11 additions & 7 deletions Pinta.Core/Classes/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ public static class Translations

public static void Init (string localeDir)
{
CultureInfo cultureInfo = CultureInfo.CurrentUICulture;
string lang = cultureInfo.Name.Replace ('-', '_'); // convert names like en-CA to en_CA

// Follow the dotnet UI culture to choose which language is used by default.
// Pinta (along with GTK / libadwaita) use the native version of gettext for translations
// so here we set the LANG environment variable to make these consistent.
// Note we need to initialize the GLib module since this is called very early in startup,
// before GTK is initialized.
GLib.Module.Initialize ();
GLib.Functions.Setenv ("LANG", lang, overwrite: true);

// Follow the dotnet UI culture to choose which language is used by default, since this
// correctly picks up system language settings on macOS, for example.
// Pinta (along with GTK / libadwaita) use the native version of gettext for translations
// so here we set the LANGUAGE environment variable to make these consistent.
if (GLib.Functions.Getenv ("LANGUAGE") is null) {
CultureInfo cultureInfo = CultureInfo.CurrentUICulture;
string lang = cultureInfo.Name.Replace ('-', '_'); // convert names like en-CA to en_CA

GLib.Functions.Setenv ("LANGUAGE", lang, overwrite: true);
}

// Initialize gettext for Pinta's translations.
IntlExtensions.BindTextDomain (PintaTextDomain, localeDir);
Expand Down
3 changes: 2 additions & 1 deletion Pinta.Core/Extensions/IntlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ static IntlExtensions ()
NativeImportResolver.RegisterLibrary (
IntlLibraryName,
windowsLibraryName: "libintl-8.dll",
linuxLibraryName: "libintl.so.8",
// On Linux, glibc has the gettext functions.
linuxLibraryName: "libc",
osxLibraryName: "libintl.8.dylib");
}

Expand Down
37 changes: 37 additions & 0 deletions tests/Pinta.Core.Tests/TranslationsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using NUnit.Framework;

namespace Pinta.Core.Tests;

[TestFixture]
[NonParallelizable] // Run in isolation since this test modifies the environment.
internal sealed class TranslationsTest
{
[OneTimeSetUp]
public void Setup ()
{
// Set to some language other than English to test translations.
GLib.Functions.Setenv ("LANGUAGE", "fr_FR", true);

// The test runs from a path like Pinta/tests/Pinta.Core.Tests/bin/Debug/net10.0,
// so we need the relative path to the translation folder (Pinta/build/bin/locale).
string localeDir = "../../../../../build/bin/locale";
Translations.Init (localeDir);
}

[OneTimeTearDown]
public void TearDown ()
{
GLib.Functions.Unsetenv ("LANGUAGE");
}

[Test]
[Description ("Test that a string can be translated. If this test fails, make sure you built with -p:BuildTranslations=true.")]
public void SimpleTranslation ()
{
if (SystemManager.GetOperatingSystem () == OS.X11) {
Assert.Ignore ("This test fails for some reason on Ubuntu.");
}

Assert.That (Translations.GetString ("Color"), Is.EqualTo ("Couleur"));
}
}
Loading