Skip to content

Commit

Permalink
Use the preselected language for extensions licenses on textmode base…
Browse files Browse the repository at this point in the history
…d installation
  • Loading branch information
imobachgs committed May 29, 2018
1 parent 0b9ca14 commit d5f74b1
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/modules/ProductLicense.rb
Expand Up @@ -657,6 +657,9 @@ def HandleLicenseDialogRet(licenses, base_product, action)
ret
end

# @return [String] Fallback language
DEFAULT_FALLBACK_LANGUAGE = "en_US".freeze

# FIXME: this is needed only by yast2-registration, fix it later
# and make this method private
#
Expand All @@ -670,6 +673,18 @@ def HandleLicenseDialogRet(licenses, base_product, action)
def DisplayLicenseDialogWithTitle(languages, back, license_language, licenses, id, caption)
languages = deep_copy(languages)

# For some languages (like Japanese, Chinese or Korean) YaST needs to use a fbiterm in order
# to display symbols correctly when running on textmode. To avoid such problems, consider only
# the preselected (on installation) or the default language (on running system). See
# bsc#1094793 for further information.
if Yast::UI.TextMode
lang = Yast::Stage.initial ? Yast::Language.preselected : Yast::Language.language
translated = languages.any? { |l| lang.start_with?(l) }
license_language = translated ? lang : DEFAULT_FALLBACK_LANGUAGE
languages = [license_language]
log.info "Adjusted license language to #{license_language}"
end

contents = (
licenses_ref = arg_ref(licenses.value)
result = GetLicenseDialog(
Expand Down
2 changes: 1 addition & 1 deletion test/lib/widgets/product_license_translations_test.rb
Expand Up @@ -64,7 +64,7 @@
widget.contents
end

context "when there is not translation for the preselected language" do
context "when there is no translation for the preselected language" do
let(:preselected) { "hu_HU" }

it "the language selector includes only 'english'" do
Expand Down
67 changes: 67 additions & 0 deletions test/product_license_test.rb
Expand Up @@ -12,6 +12,73 @@
let(:beta_file) { "README.BETA" }
subject { Yast::ProductLicense }

describe "#DisplayLicenseDialogWithTitle (partial test)" do
context "when running in text mode" do
let(:langs) { ["en_US", "ja"] }
let(:lang) { "es_ES" }
let(:licenses) { Yast.arg_ref("en_US" => "en_US license") }
let(:license_id) { "id" }
let(:preselected) { "ja_JP" }

before do
allow(Yast::Language).to receive(:GetLanguagesMap).and_return({})
allow(Yast::UI).to receive(:TextMode).and_return(true)
allow(Yast::Language).to receive(:preselected).and_return(preselected)
allow(Yast::Stage).to receive(:initial).and_return(initial)
allow(Yast::Language).to receive(:language).and_return(lang)
end

context "on the installation" do
let(:initial) { true }

it "uses the preselected language" do
expect(subject).to receive(:GetLicenseContent)
.with(preselected, anything, license_id)
subject.DisplayLicenseDialogWithTitle(
langs, "Back", lang, licenses, license_id, "License"
)
end

context "when there is no translation for the preselected language" do
let(:preselected) { "es_ES" }

it "falls back to 'english'" do
expect(subject).to receive(:GetLicenseContent)
.with("en_US", anything, license_id)
subject.DisplayLicenseDialogWithTitle(
langs, "Back", lang, licenses, license_id, "License"
)
end
end
end

context "on the installed system" do
let(:initial) { false }
let(:lang) { "ja_JP" }

it "uses the default language" do
expect(subject).to receive(:GetLicenseContent)
.with(lang, anything, license_id)
subject.DisplayLicenseDialogWithTitle(
langs, "Back", lang, licenses, license_id, "License"
)
end

context "when there is no translation for the default language" do
let(:lang) { "es_ES" }

it "falls back to 'english'" do
expect(subject).to receive(:GetLicenseContent)
.with("en_US", anything, license_id)
subject.DisplayLicenseDialogWithTitle(
langs, "Back", lang, licenses, license_id, "License"
)
end
end
end
end
end

describe "#HandleLicenseDialogRet" do
before(:each) do
# By default, always exit the dialog with :accepted (all licenses accepted)
Expand Down

0 comments on commit d5f74b1

Please sign in to comment.