Class: Y2Packager::Widgets::SimpleLanguageSelection

Inherits:
CWM::ComboBox
  • Object
show all
Defined in:
src/lib/y2packager/widgets/simple_language_selection.rb

Overview

Language selection widget

In contrast to LanguageSelection, this modules does not modify the system language in any way.

Constant Summary collapse

DEFAULT_LICENSE_LANG =
String

Default license language.

"en_US".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(languages, default) ⇒ SimpleLanguageSelection

Returns a new instance of SimpleLanguageSelection

Parameters:

  • languages (Array<String>)

    List of languages to display (en_US, de_DE, etc.)

  • default (String)

    Default language code


40
41
42
43
44
45
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 40

def initialize(languages, default)
  textdomain "packager"
  @languages = languages
  @default = default
  self.widget_id = "simple_language_selection"
end

Instance Attribute Details

#defaultString (readonly)

Returns Default language code

Returns:

  • (String)

    Default language code


34
35
36
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 34

def default
  @default
end

#languagesString (readonly)

Returns List of languages to display (en_US, de_DE, etc.)

Returns:

  • (String)

    List of languages to display (en_US, de_DE, etc.)


36
37
38
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 36

def languages
  @languages
end

Instance Method Details

#helpString

Widget help text

Returns:

  • (String)

84
85
86
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 84

def help
  ""
end

#initObject

Initialize to the given default language

If the language is not in the list of options, it will try with the short code (for instance, “de” for “de_DE”). If it fails again, its initial value will be set to “en_US”.


71
72
73
74
75
76
77
78
79
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 71

def init
  languages = items.map(&:first)
  candidates = [
    default,
    LanguageTag.new(default).generalize.to_s
  ]
  new_value = candidates.compact.find { |c| languages.include?(c) }
  self.value = new_value || DEFAULT_LICENSE_LANG
end

#itemsArray<Array<String,String>>

Return the options to be shown in the combobox

Returns:

  • (Array<Array<String,String>>)

    Array of languages in form [code, description]


91
92
93
94
95
96
97
98
99
100
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 91

def items
  return @items if @items
  lmap = Yast::Language.GetLanguagesMap(false)
  @items = languages.map do |lang|
    [lang, LanguageTag.new(lang).name(lang_map_cache: lmap)]
  end
  @items.reject! { |_lang, name| name.nil? }
  @items.uniq!
  @items.sort_by!(&:last)
end

#labelString

Widget label

Returns:

  • (String)

50
51
52
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 50

def label
  _("&Language")
end

#optObject

Widget options

Widget is forced to report immediatelly after value changed.


57
58
59
60
61
# File 'src/lib/y2packager/widgets/simple_language_selection.rb', line 57

def opt
  opts = [:notify]
  opts << :disabled unless items.size > 1
  opts
end