Class: Rlid::Language

Inherits:
Object
  • Object
show all
Defined in:
lib/rlid/common.rb

Constant Summary collapse

CODES =
[
  [:en, :eng, 'English'],
  [:es, :spa, 'Spanish'],
  [:de, :ger, 'German'],
  [:fr, :fre, 'French'],
  [:it, :ita, 'Italian'],
  [:pt, :por, 'Portoguese'],
  [:nl, :dut, 'Dutch'],
  [:pl, :pol, 'Polish'],
  [:id, :ind, 'Malay/Indonesian'],
  [:sv, :swe, 'Swedish'],
  [:tr, :tur, 'Turkish'],
  [:vi, :vie, 'Vietnamese'],
  [:ro, :rum, 'Romanian'],
  [:cs, :cze, 'Czech'],
  [:da, :dan, 'Danish'],
  [:fi, :fin, 'Finnish'],
  [:hu, :hun, 'Hungarian'],
  [:el, :ell, 'Greek'],
  [:ca, :cat, 'Catalan'],
  [:no, :nor, 'Norvegian'],
  [:sk, :slo, 'Slovak'],
  [:is, :ice, 'Icelandic'],
  #[:nn, :nnn, 'No Language']
  #[:ff, :fff], # fdakjlfdaj;
]
CODE2 =

indexes

0
CODE3 =
1
NAME =
2
NO_LANGUAGE_CODE =
:nnn

Class Method Summary collapse

Class Method Details

.all_codes2Object



39
40
41
# File 'lib/rlid/common.rb', line 39

def Language.all_codes2
  CODES.map{|c| c[CODE2]}
end

.all_codes3Object



43
44
45
# File 'lib/rlid/common.rb', line 43

def Language.all_codes3
  CODES.map{|c| c[CODE3]}
end

.code2to3(code2) ⇒ Object

def Language.each_dir

  all_codes2.each do |lang_code|
    Dir.chdir("#{DATA_DIRECTORY}/#{lang_code}") do |dir|
      yield dir
    end
  end
end


57
58
59
60
61
62
63
# File 'lib/rlid/common.rb', line 57

def Language.code2to3 code2
  begin
    CODES.select{|x| x[CODE2].to_s == code2.to_s}[0][CODE3]
  rescue
    nil
  end
end

.each_2files(filename1, filename2, mode1 = "r", mode2 = "r") ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rlid/common.rb', line 82

def Language.each_2files(filename1, filename2, mode1="r", mode2="r")
  all_codes3.each do |lang_code|
    filepath1 = "#{DATA_DIRECTORY}/#{lang_code}/#{filename1}"
    filepath2 = "#{DATA_DIRECTORY}/#{lang_code}/#{filename2}"
    File.open(filepath1, mode1) do |file1|
    File.open(filepath2, mode2) do |file2|
      yield file1, file2, lang_code
    end
    end
  end
end

.each_file(filename, mode = "r") ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/rlid/common.rb', line 73

def Language.each_file(filename, mode="r")
  all_codes3.each do |lang_code|
    filepath = "#{DATA_DIRECTORY}/#{lang_code}/#{filename}"
    File.open(filepath, mode) do |file|
      yield file, lang_code
    end
  end
end

.name_of(code) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/rlid/common.rb', line 65

def Language.name_of(code)
  if code == :nn or code == :nnn
    return "No Language"
  end
  index = all_codes3.index(code) or all_codes2.index(code)
  CODES[index][NAME]
end