/
product_license_translations.rb
83 lines (75 loc) · 2.62 KB
/
product_license_translations.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# ------------------------------------------------------------------------------
# Copyright (c) 2018 SUSE LLC, All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# ------------------------------------------------------------------------------
require "yast"
require "cwm"
require "y2country/widgets/simple_language_selection"
require "y2packager/widgets/product_license"
module Y2Packager
module Widgets
# This widget display license translations for a given product
#
# The widget serves a glue between a pair of widgets:
#
# * {Y2Country::Widgets::SimpleLanguageSelector} to select the language,
# * {Y2Packager::Widgets::ProductLicenseContent} to display the license.
class ProductLicenseTranslations < CWM::CustomWidget
# @return [Y2Packager::Product] Product
attr_reader :product
# @return [String] Language code (en_US, es_ES, etc.).
attr_reader :language
# @param product [Y2Packager::Product] Product
# @param language [String] Default language (en_US, es_ES, etc.).
def initialize(product, language)
super()
@product = product
@language = language
self.handle_all_events = true
end
# Widget content
#
# @see CWM::CustomWidget#contents
def contents
VBox(
Left(language_selection),
VSpacing(0.5),
product_license
)
end
# Event handler
#
# Translate the license content if language has changed.
#
# @param event [Hash] Event data
def handle(event)
if event["ID"] == language_selection.widget_id
product_license.translate(language_selection.value)
end
nil
end
private
# Language selection widget
#
# @return [Y2Country::Widgets::SimpleLanguageSelection]
def language_selection
@language_selection ||=
Y2Country::Widgets::SimpleLanguageSelection.new(product.license_locales, language)
end
# Product selection widget
#
# @return [Widgets::ProductLicenseContent]
def product_license
@product_license ||=
Y2Packager::Widgets::ProductLicenseContent.new(product, language)
end
end
end
end