Class: Yast::EncodingClass

Inherits:
Module
  • Object
show all
Defined in:
library/general/src/modules/Encoding.rb

Instance Method Summary collapse

Instance Method Details

#EncodingObject

Constructor does nothing in initial mode restores console encoding from /etc/sysconfig in normal mode



151
152
153
154
# File 'library/general/src/modules/Encoding.rb', line 151

def Encoding
  Restore() if !Stage.initial
  nil
end

#GetCodePage(enc) ⇒ String

Get Code Page

Parameters:

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'library/general/src/modules/Encoding.rb', line 132

def GetCodePage(enc)
  code = Ops.get_string(@enc_map, enc, "")
  if Builtins.size(code) == 0 && !@lang.nil?
    l = Builtins.substring(@lang, 0, 5)
    code = Ops.get_string(@lang_map, l, "")
  end
  Builtins.y2milestone(
    "GetCodePage enc %1 lang %2 ret %3",
    enc,
    @lang,
    code
  )
  code
end

#GetEncLangObject

Get Encoding Language

Returns:

  • Language



105
106
107
108
109
# File 'library/general/src/modules/Encoding.rb', line 105

def GetEncLang
  ret = @lang
  Builtins.y2milestone("GetEncLang ret %1", ret)
  ret
end

#GetUtf8LangBoolean

Get UTF8 Language

Returns:

  • (Boolean)


123
124
125
126
127
# File 'library/general/src/modules/Encoding.rb', line 123

def GetUtf8Lang
  ret = @utf8
  Builtins.y2milestone("GetUtf8Lang ret %1", ret)
  ret
end

#mainObject



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
# File 'library/general/src/modules/Encoding.rb', line 34

def main
  textdomain "base"

  Yast.import "Stage"

  # Current (ISO) encoding
  @console = "ISO-8859-1"
  @lang = "en_US"
  @utf8 = true

  @enc_map = {
    "euc-jp"    => "932",
    "sjis"      => "932",
    "gb2312"    => "936",
    "iso8859-2" => "852",
    "big5"      => "950",
    "euc-kr"    => "949"
  }

  @lang_map = {
    "ja_JP" => "932",
    "zh_CN" => "936",
    "zh_TW" => "950",
    "zh_HK" => "950",
    "ko_KR" => "949"
  }
  Encoding()
end

#RestoreObject

Restore data to system

Returns:

  • console encoding



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'library/general/src/modules/Encoding.rb', line 65

def Restore
  @console = Convert.to_string(
    SCR.Read(path(".sysconfig.console.CONSOLE_ENCODING"))
  )
  @console = "" if @console.nil?

  m = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), "locale -k charmap")
  )
  m = {} if m.nil?

  out = Builtins.splitstring(Ops.get_string(m, "stdout", ""), "\n")
  Builtins.y2milestone("list %1", out)

  out = Builtins.filter(out) { |e| Builtins.find(e, "charmap=") == 0 }
  Builtins.y2milestone("list %1", out)

  if Ops.greater_than(Builtins.size(Ops.get(out, 0, "")), 0)
    enc = Builtins.substring(Ops.get(out, 0, ""), 8)
    Builtins.y2milestone("enc %1", enc)
    enc = Builtins.deletechars(enc, "\" ")
    Builtins.y2milestone("enc %1", enc)
    @console = enc if Ops.greater_than(Builtins.size(enc), 0)
  end
  Builtins.y2milestone("encoding %1", @console)
  @console
end

#SetEncLang(new_lang) ⇒ void

This method returns an undefined value.

Set Encoding Language

Parameters:

  • new_lang (String)

    New Language



96
97
98
99
100
101
# File 'library/general/src/modules/Encoding.rb', line 96

def SetEncLang(new_lang)
  @lang = new_lang
  Builtins.y2milestone("SetEncLang %1", @lang)

  nil
end

#SetUtf8Lang(new_utf8) ⇒ void

This method returns an undefined value.

Set UTF8 Language

Parameters:

  • new_utf8 (Boolean)

    New UTF8 Language



114
115
116
117
118
119
# File 'library/general/src/modules/Encoding.rb', line 114

def SetUtf8Lang(new_utf8)
  @utf8 = new_utf8
  Builtins.y2milestone("SetUtf8Lang %1", @utf8)

  nil
end