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

fix: some translations moved from .po files to Config.pm #10294

Merged
merged 3 commits into from
May 14, 2024
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
2 changes: 1 addition & 1 deletion cgi/manifest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

my $request_ref = ProductOpener::Display::init_request();

my $short_name = lang("site_name");
my $short_name = $options{site_name};
my $long_name = $short_name;

# https://stackoverflow.com/a/16533563/11963
Expand Down
2 changes: 1 addition & 1 deletion cgi/opensearch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

# https://developer.mozilla.org/en-US/Add-ons/Creating_OpenSearch_plugins_for_Firefox
# Maximum of 16 characters
my $short_name = lang("site_name");
my $short_name = $options{site_name};
# Maximum of 48 characters
my $long_name = $short_name;
if ($cc eq 'world') {
Expand Down
2 changes: 1 addition & 1 deletion cgi/product_image.pl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

my $photographer = $product_ref->{images}{$id}{uploader};
my $editor = $photographer;
my $site_name = lang('site_name');
my $site_name = $options{site_name};

my $original_id = $product_ref->{images}{$id}{imgid};
my $original_link = "";
Expand Down
3 changes: 2 additions & 1 deletion cgi/user.pl
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@
$template_data_ref->{add_user_pro_url} = sprintf(lang("add_user_you_can_edit_pro_promo"), $pro_url);

$template_data_ref->{add_user_you_can_edit} = sprintf(lang("add_user_you_can_edit"), lang("get_the_app_link"));
$template_data_ref->{add_user_join_the_project} = sprintf(lang("add_user_join_the_project"), lang("site_name"));
$template_data_ref->{add_user_join_the_project}
= sprintf(lang("add_user_join_the_project"), $options{site_name});
}

}
Expand Down
2 changes: 2 additions & 0 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ $flavor = 'off';
android_app_link => "https://world.openfoodfacts.org/files/off.apk",
ios_app_link => "https://apps.apple.com/app/open-food-facts/id588797948",
facebook_page_url => "https://www.facebook.com/OpenFoodFacts",
facebook_page_url_fr => "https://www.facebook.com/OpenFoodFacts.fr",
twitter_account => "OpenFoodFacts",
twitter_account_fr => "OpenFoodFactsFr",
);

$options{export_limit} = 10000;
Expand Down
10 changes: 5 additions & 5 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7217,12 +7217,12 @@ sub display_page ($request_ref) {
my $join_us_on_slack
= sprintf($Lang{footer_join_us_on}{$lc}, '<a href="https://slack.openfoodfacts.org">Slack</a>');

my $twitter_account = lang("twitter_account");
if (defined $Lang{twitter_account_by_country}{$cc}) {
$twitter_account = $Lang{twitter_account_by_country}{$cc};
}
# Twitter account and Facebook page url from Config.pm
# Allow to have language specific Twitter accounts and Facebook page url, suffixed by the language code
my $twitter_account = $options{"twitter_account_$lc"} || $options{twitter_account};
$template_data_ref->{twitter_account} = $twitter_account;
# my $facebook_page = lang("facebook_page");
my $facebook_page = $options{"facebook_page_url_$lc"} || $options{facebook_page_url};
$template_data_ref->{facebook_page_url} = $facebook_page;

my $torso_class = "anonymous";
if (defined $User_id) {
Expand Down
44 changes: 26 additions & 18 deletions lib/ProductOpener/Lang.pm
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,14 @@ if (-e $path) {
$log->info("Loaded \%Lang", {path => $path}) if $log->is_info();

# Initialize @Langs and $lang_lc
@Langs = sort keys %{$Lang{site_name}}
; # any existing key can be used, as %Lang should contain values for all languages for all keys
# any existing key can be used, as %Lang should contain values for all languages for all keys
my $msgctxt = "add";
if (not defined $Lang{$msgctxt}) {
$log->error("Language translation file does not contain the 'add' key, \%Lang will be empty.", {path => $path})
if $log->is_error();
die("Language translation file does not contain the 'add' key, \%Lang will be empty.");
}
@Langs = sort keys %{$Lang{$msgctxt}};
%Langs = ();
%lang_lc = ();
foreach my $l (@Langs) {
Expand Down Expand Up @@ -424,8 +430,10 @@ sub build_lang ($Languages_ref) {
# print $fh "Lang.pm - %Lang\n\n" . eDumper(\%Lang) . "\n";
# close $fh;

my $missing_english_translations = 0;

foreach my $key (keys %Lang) {
if ((defined $Lang{$key}{fr}) or (defined $Lang{$key}{en})) {
if ((defined $Lang{$key}{en}) and ($Lang{$key}{en} ne '')) {
foreach my $l (@Langs) {

my $short_l = undef;
Expand All @@ -448,24 +456,27 @@ sub build_lang ($Languages_ref) {
my $tagid = get_string_id_for_lang($l, $Lang{$key}{$l});
}
}
elsif ($key !~ /\__/) {
$log->error("No English translation for $key") if $log->is_error();
print STDERR "No English translation for $key\n";
$missing_english_translations++;
}
}

my @special_fields = ("site_name");
if ($missing_english_translations) {
$log->error("Missing English translations: $missing_english_translations") if $log->is_error();
die("$missing_english_translations English translations are missing, please fix them in the .po files");
}

foreach my $special_field (@special_fields) {
# Some translations have <<site_name>> in them, replace it with the site name
my $site_name = $options{site_name};

foreach my $l (@Langs) {
my $value = $Lang{$special_field}{$l};
if (not(defined $value)) {
foreach my $l (@Langs) {
foreach my $key (keys %Lang) {
if (not defined $Lang{$key}{$l}) {
next;
}

foreach my $key (keys %Lang) {
if (not defined $Lang{$key}{$l}) {
next;
}
$Lang{$key}{$l} =~ s/\<\<$special_field\>\>/$value/g;
}
$Lang{$key}{$l} =~ s/\<\<site_name\>\>/$site_name/g;
}
}

Expand Down Expand Up @@ -531,9 +542,6 @@ sub build_json {
elsif ((defined $Lang{$s}{en}) and ($Lang{$s}{en} ne '')) {
$value = $Lang{$s}{en};
}
elsif (defined $Lang{$s}{fr}) {
$value = $Lang{$s}{fr};
}

$result{$s} = $value if $value;
}
Expand Down
13 changes: 8 additions & 5 deletions lib/ProductOpener/Mail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ sub send_email ($user_ref, $subject, $text) {
my $name = $user_ref->{name};

$text =~ s/<NAME>/$name/g;
my $mail = Email::Stuffer->from(lang("site_name") . " <$contact_email>")->to($name . " <$email>")->subject($subject)
my $mail
= Email::Stuffer->from($options{site_name} . " <$contact_email>")->to($name . " <$email>")->subject($subject)
->text_body($text);
return _send_email($mail);
}
Expand Down Expand Up @@ -195,7 +196,8 @@ sub send_html_email ($user_ref, $subject, $html_content) {
my $email = $user_ref->{email};
my $name = $user_ref->{name};

my $mail = Email::Stuffer->from(lang("site_name") . " <$contact_email>")->to($name . " <$email>")->subject($subject)
my $mail
= Email::Stuffer->from($options{site_name} . " <$contact_email>")->to($name . " <$email>")->subject($subject)
->html_body($html_content);
return _send_email($mail);
}
Expand Down Expand Up @@ -257,7 +259,8 @@ On the other hand, if there was no error, it returns 0 indicating that the email
=cut

sub send_email_to_admin ($subject, $text) {
my $mail = Email::Stuffer->from(lang("site_name") . " <$contact_email>")->to(lang("site_name") . " <$admin_email>")
my $mail
= Email::Stuffer->from($options{site_name} . " <$contact_email>")->to($options{site_name} . " <$admin_email>")
->subject($subject)->text_body($text);

return _send_email($mail);
Expand All @@ -284,8 +287,8 @@ On the other hand, if there was no error, it returns 1 indicating that email has

sub send_email_to_producers_admin ($subject, $text) {
my $mail
= Email::Stuffer->from(lang("site_name") . " <$contact_email>")->to(lang("site_name") . " <$producers_email>")
->subject($subject)->text_body($text)->html_body($text);
= Email::Stuffer->from($options{site_name} . " <$contact_email>")
->to($options{site_name} . " <$producers_email>")->subject($subject)->text_body($text)->html_body($text);

return _send_email($mail);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/ProductOpener/Tags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,7 @@ sub init_countries() {
%country_codes_reverse = ();
%country_languages = ();

foreach my $country (keys %{$properties{countries}}) {
foreach my $country (sort keys %{$properties{countries}}) {

my $cc = country_to_cc($country);
if (not(defined $cc)) {
Expand All @@ -2659,10 +2659,12 @@ sub init_countries() {
my $nameid = get_string_id_for_lang("no_language", $name);
if (not defined $country_names{$nameid}) {
$country_names{$nameid} = [$cc, $country, $language];
# print STDERR "country_names{$nameid} = [$cc, $country, $language]\n";
}
}
}
else {
$log->warn("No language_codes:en for country $country") if $log->is_warn();
}
}
return;
}
Expand Down
14 changes: 7 additions & 7 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,7 @@ msgstr "view"

msgctxt "view_this_revision"
msgid "View this revision"
msgstr ""
msgstr "View this revision"

msgctxt "view_list_for_products_from_the_entire_world"
msgid "View the list for matching products from the entire world"
Expand Down Expand Up @@ -6814,27 +6814,27 @@ msgstr "sweetener"

msgctxt "action_edit_product"
msgid "Complete or correct product information"
msgstr ""
msgstr "Complete or correct product information"

msgctxt "report_problem_panel_title"
msgid "Report a problem"
msgstr ""
msgstr "Report a problem"

msgctxt "incomplete_or_incorrect_data_title"
msgid "Incomplete or incorrect information?"
msgstr ""
msgstr "Incomplete or incorrect information?"

msgctxt "incomplete_or_incorrect_data_subtitle_off"
msgid "Category, labels, ingredients, allergens, nutritional information, photos etc."
msgstr ""
msgstr "Category, labels, ingredients, allergens, nutritional information, photos etc."

msgctxt "incomplete_or_incorrect_data_content_correct"
msgid "If the information does not match the information on the packaging, you can complete or correct it. Thank you!"
msgstr ""
msgstr "If the information does not match the information on the packaging, you can complete or correct it. Thank you!"

msgctxt "incomplete_or_incorrect_data_content_correct_off"
msgid "Open Food Facts is a collaborative database, and every contribution is useful for all."
msgstr ""
msgstr "Open Food Facts is a collaborative database, and every contribution is useful for all."

msgctxt "description"
msgid "Description"
Expand Down
8 changes: 0 additions & 8 deletions po/common/ia.po
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ msgid ""
"<img src=\"/images/misc/android-apk.svg\" loading=\"lazy\" alt=\"Android APK\" />"
msgstr ""

msgctxt "android_apk_app_link"
msgid "https://world.openfoodfacts.org/files/off.apk"
msgstr "https://world.openfoodfacts.org/files/off.apk"

msgctxt "android_app_badge"
msgid ""
"<img src=\"/images/misc/android-app-on-google-play-"
Expand Down Expand Up @@ -2431,10 +2427,6 @@ msgid ""
"information on food products from around the world"
msgstr ""

msgctxt "site_name"
msgid "Open Food Facts"
msgstr "Open Food Facts"

msgctxt "sort_by"
msgid "Sort by"
msgstr ""
Expand Down
9 changes: 0 additions & 9 deletions po/common/kmr.po
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ msgctxt "android_apk_app_icon_alt_text"
msgid "Android APK"
msgstr ""

# DO NOT TRANSLATE
msgctxt "android_apk_app_link"
msgid "https://world.openfoodfacts.org/files/off.apk"
msgstr ""

# Please change en_get.svg to fr_get.svg. check the url https://static.openfoodfacts.org/images/misc/playstore/img/XX_get.svg
msgctxt "android_app_icon_url"
msgid "/images/misc/playstore/img/en_get.svg"
Expand Down Expand Up @@ -2304,10 +2299,6 @@ msgctxt "site_description"
msgid "A collaborative, free and open database of ingredients, nutrition facts and information on food products from around the world"
msgstr ""

msgctxt "site_name"
msgid "Open Food Facts"
msgstr "Open Food Facts"

msgctxt "logo_site_name"
msgid "Open Food Facts logo"
msgstr ""
Expand Down
9 changes: 0 additions & 9 deletions po/common/ku.po
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ msgctxt "android_apk_app_icon_alt_text"
msgid "Android APK"
msgstr ""

# DO NOT TRANSLATE
msgctxt "android_apk_app_link"
msgid "https://world.openfoodfacts.org/files/off.apk"
msgstr ""

# Please change en_get.svg to fr_get.svg. check the url https://static.openfoodfacts.org/images/misc/playstore/img/XX_get.svg
msgctxt "android_app_icon_url"
msgid "/images/misc/playstore/img/en_get.svg"
Expand Down Expand Up @@ -2304,10 +2299,6 @@ msgctxt "site_description"
msgid "A collaborative, free and open database of ingredients, nutrition facts and information on food products from around the world"
msgstr ""

msgctxt "site_name"
msgid "Open Food Facts"
msgstr "Open Food Facts"

msgctxt "logo_site_name"
msgid "Open Food Facts logo"
msgstr ""
Expand Down
9 changes: 0 additions & 9 deletions po/common/me.po
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ msgctxt "android_apk_app_icon_alt_text"
msgid "Android APK"
msgstr ""

# DO NOT TRANSLATE
msgctxt "android_apk_app_link"
msgid "https://world.openfoodfacts.org/files/off.apk"
msgstr ""

# Please change en_get.svg to fr_get.svg. check the url https://static.openfoodfacts.org/images/misc/playstore/img/XX_get.svg
msgctxt "android_app_icon_url"
msgid "/images/misc/playstore/img/en_get.svg"
Expand Down Expand Up @@ -2306,10 +2301,6 @@ msgctxt "site_description"
msgid "A collaborative, free and open database of ingredients, nutrition facts and information on food products from around the world"
msgstr ""

msgctxt "site_name"
msgid "Open Food Facts"
msgstr "Open Food Facts"

msgctxt "logo_site_name"
msgid "Open Food Facts logo"
msgstr ""
Expand Down
9 changes: 0 additions & 9 deletions po/common/ry.po
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ msgctxt "android_apk_app_icon_alt_text"
msgid "Android APK"
msgstr ""

# DO NOT TRANSLATE
msgctxt "android_apk_app_link"
msgid "https://world.openfoodfacts.org/files/off.apk"
msgstr ""

# Please change en_get.svg to fr_get.svg. check the url https://static.openfoodfacts.org/images/misc/playstore/img/XX_get.svg
msgctxt "android_app_icon_url"
msgid "/images/misc/playstore/img/en_get.svg"
Expand Down Expand Up @@ -2306,10 +2301,6 @@ msgctxt "site_description"
msgid "A collaborative, free and open database of ingredients, nutrition facts and information on food products from around the world"
msgstr ""

msgctxt "site_name"
msgid "Open Food Facts"
msgstr "Open Food Facts"

msgctxt "logo_site_name"
msgid "Open Food Facts logo"
msgstr ""
Expand Down
9 changes: 0 additions & 9 deletions po/common/sh.po
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ msgctxt "android_apk_app_icon_alt_text"
msgid "Android APK"
msgstr ""

# DO NOT TRANSLATE
msgctxt "android_apk_app_link"
msgid "https://world.openfoodfacts.org/files/off.apk"
msgstr ""

# Please change en_get.svg to fr_get.svg. check the url https://static.openfoodfacts.org/images/misc/playstore/img/XX_get.svg
msgctxt "android_app_icon_url"
msgid "/images/misc/playstore/img/en_get.svg"
Expand Down Expand Up @@ -2306,10 +2301,6 @@ msgctxt "site_description"
msgid "A collaborative, free and open database of ingredients, nutrition facts and information on food products from around the world"
msgstr ""

msgctxt "site_name"
msgid "Open Food Facts"
msgstr "Open Food Facts"

msgctxt "logo_site_name"
msgid "Open Food Facts logo"
msgstr ""
Expand Down
Loading
Loading