From 89bd4624bdfc857de359c482a95d927199042da2 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 20 May 2019 11:01:34 +0200 Subject: [PATCH] Avoid breaking the build of yast2.rpm (bsc#1130822) If /usr/share/YaST2/locale does not exist (eg. during the building of yast2.rpm) FastGettext will complain. So in that case bail out of `textdomain` and `_`+friends. Here's how it broke without this fix: +Log No textdomain configured in Yast::CommandLineClass, cannot translate "Print the help for this module" The log line *appears* because it is now reported at CommandLine.rb (previously i18n.rb) which matches the "testedfiles" filter of the testsuite. The error *happens* the "textdomain" method returns early before remembering its argument. --- src/ruby/yast/i18n.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ruby/yast/i18n.rb b/src/ruby/yast/i18n.rb index b9299153..5ff4e29c 100644 --- a/src/ruby/yast/i18n.rb +++ b/src/ruby/yast/i18n.rb @@ -53,10 +53,12 @@ def textdomain(domain) # usually without brackets like textdomain "example" def _(str) # no textdomain configured yet if !@my_textdomain - msg = "No textdomain configured in #{self.class}, " \ - "cannot translate #{str.inspect}" - raise msg if ENV["Y2STRICTTEXTDOMAIN"] - Yast.y2warning(1, "%1", msg) # skip 1 frame + if File.exist?(LOCALE_DIR) + msg = "No textdomain configured in #{self.class}, " \ + "cannot translate #{str.inspect}" + raise msg if ENV["Y2STRICTTEXTDOMAIN"] + Yast.y2warning(1, "%1", msg) # skip 1 frame + end return str.freeze end @@ -123,11 +125,13 @@ def Nn_(*keys) def n_(singular, plural, num) # no textdomain configured yet if !@my_textdomain - # it's enough to log just the singular form - msg = "No textdomain configured in #{self.class}, " \ - "cannot translate #{singular.inspect}" - raise msg if ENV["Y2STRICTTEXTDOMAIN"] - Yast.y2warning(1, "%1", msg) # skip 1 frame + if File.exist?(LOCALE_DIR) + # it's enough to log just the singular form + msg = "No textdomain configured in #{self.class}, " \ + "cannot translate #{singular.inspect}" + raise msg if ENV["Y2STRICTTEXTDOMAIN"] + Yast.y2warning(1, "%1", msg) # skip 1 frame + end return fallback_n_(singular, plural, num) end