Module: Core::Trans
- Defined in:
- lib/translate.rb
Constant Summary collapse
- SUB =
"[SUBSTITUTE]"
- @@items =
TODO auto-setup hashes, this is crap languages must be loaded from the available folders
{ "de" => {}, "en" => {}, }
- @@skills =
{ "de" => {}, "en" => {}, }
- @@spells =
{ "de" => {}, "en" => {}, }
- @@dialogues =
{ "de" => {}, "en" => {}, }
- @@enemies =
{ "de" => {}, "en" => {}, }
- @@weapons =
{ "de" => {}, "en" => {}, }
{ "de" => { :menu => "Menü", :titlescreen_title => "Ewige Hoffnung", :newgame => "Neues Spiel", :loadgame => "Spiel laden", :options => "Optionen", :update => "Update", :items => "Gegenstände", :item => "Gegenstand", :equipment => "Ausrüstung", :skills => "Fertigkeiten", :skill => "Fertigkeit", :magic => "Magie", :save => "Speichern", :load => "Laden", :language => "Sprache", :options_details => "Details", :volume => "Lautstärke", :lang_english => "Englisch", :lang_german => "Deutsch", :restart_warning => "Das Spiel muss neugestartet werden, um alle Einstellungen zu übernehmen.", :walk_here => "Hingehen", :ground => "Boden", :you => "Du", :talk_to => "Ansprechen", :attack => "Angreifen", :abort => "Abbrechen", :select_spell => "Zauber auswählen", :botany => "Kräuterkunde", :experience => "Erfahrung", :xp_none => "Keine", :xp_vlittle => "Sehr wenig", :xp_little => "Wenig", :xp_mediocre => "Mittelmäßig", :xp_experienced => "Erfahren", :xp_vexperienced => "Sehr erfahren", :recipies => "Rezepte", }, "en" => { :menu => "Menu", :titlescreen_title => "Ewige Hoffnung", :newgame => "New Game", :loadgame => "Load Game", :options => "Options", :update => "Update", :items => "Items", :item => "Item", :equipment => "Equipment", :skills => "Skills", :skill => "Skill", :magic => "Magic", :save => "Save", :load => "Load", :language => "Language", :options_details => "Details", :volume => "Volume", :lang_english => "English", :lang_german => "German", :restart_warning => "The game must be restarted to apply all settings.", :walk_here => "Walk here", :ground => "Ground", :you => "You", :talk_to => "Talk to", :attack => "Attack", :abort => "Abort", :select_spell => "Select spell", :botany => "Herbal lore", :experience => "Experience", :xp_none => "None", :xp_vlittle => "Very little", :xp_little => "Little", :xp_mediocre => "Mediocre", :xp_experienced => "Experienced", :xp_vexperienced => "Very experienced", :recipies => "Recipies", }, }
Class Method Summary collapse
- .dialogue(sym, replace = nil) ⇒ Object
- .enemy(sym) ⇒ Object
- .handle_failed(type) ⇒ Object
- .item(sym) ⇒ Object
- .menu(sym, replace = nil) ⇒ Object
- .parse_dialogues ⇒ Object
- .parse_enemies ⇒ Object
- .parse_items ⇒ Object
- .parse_skills ⇒ Object
- .parse_spells ⇒ Object
- .safe(hash, sym, replace = nil) ⇒ Object
- .skill(sym) ⇒ Object
- .spell(sym) ⇒ Object
- .weapon(sym) ⇒ Object
Class Method Details
.dialogue(sym, replace = nil) ⇒ Object
358 359 360 |
# File 'lib/translate.rb', line 358 def self.dialogue(sym, replace=nil) return safe(@@dialogues, sym, replace) end |
.enemy(sym) ⇒ Object
361 362 363 |
# File 'lib/translate.rb', line 361 def self.enemy(sym) return safe(@@enemies, sym) end |
.handle_failed(type) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/translate.rb', line 319 def self.handle_failed(type) puts("FATAL: No #{type} translations for selected language (#{Core.config[:language]}) found!") if Core.config[:language] != "de" Core.config[:language] = "de" puts("INFO: Changed language to 'de' (German), try restarting") Core.exit(1) else puts("INFO: Even the default language is not working, the install seems to be broken.\nTry redownloading the application.") Core.exit(1) end end |
.item(sym) ⇒ Object
346 347 348 |
# File 'lib/translate.rb', line 346 def self.item(sym) return safe(@@items, sym) end |
.menu(sym, replace = nil) ⇒ Object
355 356 357 |
# File 'lib/translate.rb', line 355 def self.(sym, replace=nil) return safe(@@menu, sym, replace) end |
.parse_dialogues ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/translate.rb', line 237 def self.parse_dialogues Dir.new("#{Core::LIBRARY_PATH}/def/#{Core.config[:language]}/dialogues/").each { |f| begin if File.directory?("#{Core::LIBRARY_PATH}/#{f}") or File.extname("#{Core::LIBRARY_PATH}/#{f}") != ".dlg" next end file = File.new("#{Core::LIBRARY_PATH}/def/#{Core.config[:language]}/dialogues/#{f}") block = false msg = "" sym = nil file.each_line { |line| line.gsub!("\n", "") if line.start_with?("#") or line.length == 0 if line == "#EOF" break end next end line.lstrip! if block if line.include?("}") block = false @@dialogues[Core.config[:language]].store(sym, msg) msg = "" sym = nil next end msg += "#{line}\n" else if line.include?("{") block = true sym = line.gsub(/\s?\{/, "").to_sym end end } file.close rescue Errno::ENOENT end } end |
.parse_enemies ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/translate.rb', line 278 def self.parse_enemies begin file = File.open("#{Core::LIBRARY_PATH}/def/#{Core.config[:language]}/enemies.trans", "r") block = false name = desc = "" enemy = nil file.each_line { |line| line.gsub!("\n", "") if line.start_with?("#") or line.length == 0 if line == "#EOF" break end next end if line[0] == "{" block = true end if line[0] == "}" block = false @@enemies[Core.config[:language]].store(enemy.name, name) @@enemies[Core.config[:language]].store("#{enemy.name}_desc", desc) next end if block if line.start_with?("name") line.gsub!(/name *= */, "") name = line.gsub("\"", "") elsif line.start_with?("desc") line.gsub!(/desc *= */, "") desc = line.gsub("\"", "") end else enemy = Core::Game.find_enemy(line.to_sym) end } file.close rescue Errno::ENOENT self.handle_failed("skill") end end |
.parse_items ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/translate.rb', line 114 def self.parse_items begin file = File.open("#{Core::LIBRARY_PATH}/def/#{Core.config[:language]}/items.trans", "r") block = false name = desc = "" item = nil file.each_line { |line| line.gsub!("\n", "") if line.start_with?("#") or line.length == 0 if line == "#EOF" break end next end if line[0] == "{" block = true end if line[0] == "}" block = false @@items[Core.config[:language]].store(item.name, name) @@items[Core.config[:language]].store("#{item.name}_desc", desc) next end if block if line.start_with?("name") line.gsub!(/name *= */, "") name = line.gsub("\"", "") elsif line.start_with?("desc") line.gsub!(/desc *= */, "") desc = line.gsub("\"", "") end else item = Core::Game.find_item(line.to_sym) end } file.close rescue Errno::ENOENT self.handle_failed("item") end end |
.parse_skills ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/translate.rb', line 196 def self.parse_skills begin file = File.open("#{Core::LIBRARY_PATH}/def/#{Core.config[:language]}/skills.trans", "r") block = false name = desc = "" skill = nil file.each_line { |line| line.gsub!("\n", "") if line.start_with?("#") or line.length == 0 if line == "#EOF" break end next end if line[0] == "{" block = true end if line[0] == "}" block = false @@skills[Core.config[:language]].store(skill.name, name) @@skills[Core.config[:language]].store("#{skill.name}_desc", desc) next end if block if line.start_with?("name") line.gsub!(/name *= */, "") name = line.gsub("\"", "") elsif line.start_with?("desc") line.gsub!(/desc *= */, "") desc = line.gsub("\"", "") end else skill = Core::Game.find_skill(line.to_sym) end } file.close rescue Errno::ENOENT self.handle_failed("skill") end end |
.parse_spells ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/translate.rb', line 155 def self.parse_spells begin file = File.open("#{Core::LIBRARY_PATH}/def/#{Core.config[:language]}/spells.trans", "r") block = false name = desc = "" spell = nil file.each_line { |line| line.gsub!("\n", "") if line.start_with?("#") or line.length == 0 if line == "#EOF" break end next end if line[0] == "{" block = true end if line[0] == "}" block = false @@spells[Core.config[:language]].store(spell.name, name) @@spells[Core.config[:language]].store("#{spell.name}_desc".to_sym, desc) next end if block if line.start_with?("name") line.gsub!(/name *= */, "") name = line.gsub("\"", "") elsif line.start_with?("desc") line.gsub!(/desc *= */, "") desc = line.gsub("\"", "") end else spell = Core::Game.find_spell(line.to_sym) end } file.close rescue Errno::ENOENT self.handle_failed("spell") end end |
.safe(hash, sym, replace = nil) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/translate.rb', line 331 def self.safe(hash, sym, replace=nil) if !hash.has_key?(Core.config[:language]) warn("ERROR: Selected language (#{Core.config[:language]}) not available") return "" elsif !hash[Core.config[:language]].has_key?(sym) warn("ERROR: Missing translation for #{sym} for language #{Core.config[:language]}") return "" end if replace && !replace.empty? return hash[Core.config[:language]][sym].gsub(SUB, replace) else return hash[Core.config[:language]][sym] end end |
.skill(sym) ⇒ Object
349 350 351 |
# File 'lib/translate.rb', line 349 def self.skill(sym) return safe(@@skills, sym) end |
.spell(sym) ⇒ Object
352 353 354 |
# File 'lib/translate.rb', line 352 def self.spell(sym) return safe(@@spells, sym) end |
.weapon(sym) ⇒ Object
364 365 366 |
# File 'lib/translate.rb', line 364 def self.weapon(sym) return safe(@@weapons, sym) end |