Class: Umu::LanguageSetting
- Inherits:
-
Object
- Object
- Umu::LanguageSetting
show all
- Extended by:
- Template
- Defined in:
- lib/umu/core/language_setting.rb
Overview
LanguageSetting is a module for setting language.
Constant Summary
collapse
- LANG =
{
en: 'English',
zh: '中文',
ja: '日本語'
}.freeze
- LANG_PATH =
File.join(File.dirname(__FILE__), '../../..', '.umu_lang')
Constants included
from Color
Color::COLORS
Class Method Summary
collapse
Methods included from Template
checker, command, cover, hover, logo, pointer, show_command
Class Method Details
.change_language ⇒ Object
41
42
43
44
|
# File 'lib/umu/core/language_setting.rb', line 41
def self.change_language
File.exist?(LANG_PATH) ? File.delete(LANG_PATH) : nil
setup_language
end
|
.prompt_language ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/umu/core/language_setting.rb', line 26
def self.prompt_language
logo
content = 'Please select a language:'
item = Umu::Selector.radio(LANG.values, content)
cover(1)
puts "#{content} #{green(item)}"
LANG.key(item)
end
|
.save_language_choice(lang) ⇒ Object
35
36
37
38
39
|
# File 'lib/umu/core/language_setting.rb', line 35
def self.save_language_choice(lang)
umu_lang = {}
umu_lang['language'] = lang
File.write(LANG_PATH, umu_lang.to_yaml)
end
|
.setup_language ⇒ Object
19
20
21
22
23
24
|
# File 'lib/umu/core/language_setting.rb', line 19
def self.setup_language
save_language_choice(prompt_language) unless File.exist?(LANG_PATH)
umu_lang = YAML.load_file(LANG_PATH)
lang = umu_lang['language']
I18n.locale = lang
end
|