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

l10n: Correctly setup the locales #8

Open
wants to merge 1 commit into
base: localization
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ i18n = import('i18n')
# Set our translation domain
add_global_arguments('-DGETTEXT_PACKAGE="@0@"'.format (meson.project_name()), language:'c')

config_data = configuration_data()
# Provide a path of the directory where translation binary files (*.mo) are located
config_data.set_quoted('LOCALEDIR', get_option('prefix') / get_option('localedir'))
# Provide translation domain name
config_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the same as project ID can we just assume this is also always the same as application ID? It feels like kinda overkill to use a config file for this if we know it's equal to a variable we're already using in the application class

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the same as project ID can we just assume this is also always the same as application ID?

Hmm, I don't think so, because I think it's by chance that the GETTEXT_PACKAGE in the config file is same as the application ID in this example.

We can set a value to GETTEXT_PACKAGE that is different from the application ID. And in that case, it's meson.build that knows the original value of GETTEXT_PACKAGE, as you can see at ryonakano@5d4c2e1. So I think it's reasonable to set GETTEXT_PACKAGE as a configuration data here and don't think it's overkill, even if these values are equal.

config_file = configure_file(
input: 'src' / 'Config.vala.in',
output: '@BASENAME@',
configuration: config_data
)

# Create a new executable, list the files we want to compile, list the dependencies we need, and install
executable(
meson.project_name(),
config_file,
'src' / 'Application.vala',
dependencies: [
dependency('gtk4')
Expand Down
5 changes: 5 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class MyApp : Gtk.Application {
}

public static int main (string[] args) {
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);

return new MyApp ().run (args);
}
}
3 changes: 3 additions & 0 deletions src/Config.vala.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// The values put inside "@" are replaced in accordance with the configuration data by meson
public const string GETTEXT_PACKAGE = @GETTEXT_PACKAGE@;
public const string LOCALEDIR = @LOCALEDIR@;