Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 1882 Bytes
1 | require 'iconv' |
2 | |
3 | module RForum; module Localization |
4 | |
5 | LOCALIZED_STRINGS = {} |
6 | |
7 | def l(*a) RForum::Localization.l(*a) end |
8 | |
9 | def self.l(symbol, *arguments) |
10 | language = RForum::CONFIG[:default_language] |
11 | |
12 | symbol = symbol.to_sym if symbol.is_a? String |
13 | |
14 | # translation of an LString is simply a call to to_s |
15 | return symbol.to_s if symbol.is_a? LString |
16 | |
17 | # translation of an array |
18 | if symbol.is_a? Array |
19 | raise ArgumentError.new("Cannot translate an empty array") if symbol.empty? |
20 | raise ArgumentError.new("Symbol is an array, arguments must be empty") unless arguments.empty? |
21 | arguments = symbol |
22 | symbol = arguments.shift |
23 | end |
24 | |
25 | translation = (LOCALIZED_STRINGS[language][symbol] or |
26 | LOCALIZED_STRINGS['en'][symbol] or |
27 | symbol.to_s) |
28 | begin |
29 | return translation % arguments |
30 | rescue => e |
31 | raise ArgumentError.new("Translation value #{translation.inspect} " + |
32 | "with arguments #{arguments.inspect} caused error '#{e.message}'") |
33 | end |
34 | end |
35 | |
36 | def valid_language?(language) |
37 | LOCALIZED_STRINGS.has_key? language |
38 | end |
39 | |
40 | def self.load_localized_strings |
41 | # Load language files |
42 | Dir[RAILS_ROOT + '/lang/*.yaml'].each do |filename| |
43 | filename =~ /([a-z]+)\.yaml$/ |
44 | hash = YAML::load(File.read(filename)) |
45 | file_charset = hash['file_charset'] || 'ascii' |
46 | |
47 | # convert string keys to symbols |
48 | symbol_hash = Hash.new |
49 | Iconv.open(RForum::CONFIG[:web_charset], file_charset) do |i| |
50 | hash.each do |key, value| |
51 | symbol_hash[key.to_sym] = i.iconv(value) |
52 | end |
53 | end |
54 | |
55 | LOCALIZED_STRINGS[$1] = symbol_hash |
56 | end |
57 | end |
58 | |
59 | class LString |
60 | |
61 | include RForum::Localization |
62 | |
63 | def initialize(symbol, arguments) |
64 | @symbol, @arguments = symbol, arguments |
65 | end |
66 | |
67 | def to_s |
68 | l(@symbol, @arguments) |
69 | end |
70 | end |
71 | |
72 | end; end |