r18n-desktop 0.3.2 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +34 -28
- data/lib/r18n-desktop.rb +28 -4
- data/spec/r18n-desktop_spec.rb +11 -6
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
= R18n Desktop
|
2
2
|
|
3
|
-
A tool to translate your desktop application
|
3
|
+
A tool to translate your desktop application to several languages.
|
4
4
|
|
5
|
-
It is just a
|
5
|
+
It is just a wrapper for R18n core library. See R18n documentation for more
|
6
6
|
information.
|
7
7
|
|
8
8
|
== Features
|
9
9
|
|
10
|
-
*
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
*
|
15
|
-
|
16
|
-
*
|
17
|
-
* It storage translation in rich YAML format. You can put procedures and
|
18
|
-
pluralization (“1 comment”, “5 comments”) or create you own filters.
|
10
|
+
* Nice Ruby-style syntax.
|
11
|
+
* Filters.
|
12
|
+
* Flexible locales.
|
13
|
+
* Custom translations loaders.
|
14
|
+
* Translation support for any classes.
|
15
|
+
* Time and number localization.
|
16
|
+
* Several user language support.
|
19
17
|
|
20
18
|
== How To
|
19
|
+
|
21
20
|
1. Create translations dir. For example: <tt>./i18n/</tt>.
|
22
21
|
2. Add file with translation in some language. For example
|
23
22
|
<tt>./i18n/en.yml</tt>:
|
@@ -30,8 +29,6 @@ information.
|
|
30
29
|
0: No files
|
31
30
|
1: One file
|
32
31
|
n: %1 files
|
33
|
-
|
34
|
-
author: !!proc |name| "This file was created by #{name.capitalize}"
|
35
32
|
|
36
33
|
3. Add R18n to your application:
|
37
34
|
|
@@ -39,33 +36,42 @@ information.
|
|
39
36
|
|
40
37
|
4. Load I18n object:
|
41
38
|
|
42
|
-
|
39
|
+
R18n.from_env 'i18n/'
|
43
40
|
|
44
41
|
Or, if user can optional set locale manually:
|
45
42
|
|
46
|
-
|
43
|
+
R18n.from_env 'i18n/', manual_locale
|
44
|
+
|
45
|
+
5. Include mixin to use helpers:
|
47
46
|
|
48
|
-
|
47
|
+
include R18n::Helpers
|
48
|
+
|
49
|
+
6. Use translation messages to user. For example:
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
i18n.author('user') #=> "This file was created by User"
|
55
|
-
|
56
|
-
i18n.l -12000.5 #=> "−12,000.5"
|
51
|
+
t.file.add #=> "Add file"
|
52
|
+
t.file.delete('Test') #=> "Delete file Test"
|
53
|
+
t.files(1) #=> "One file"
|
54
|
+
t.files(12) #=> "12 files"
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
l -12000.5 #=> "−12,000.5"
|
57
|
+
l Time.now #=> "08/09/2009 21:41"
|
58
|
+
l Time.now, :human #=> "now"
|
59
|
+
l Time.now, :full #=> "August 9th, 2009 21:41"
|
61
60
|
|
62
61
|
# Base translation
|
63
|
-
|
64
|
-
|
62
|
+
t.ok #=> "OK"
|
63
|
+
t.cancel #=> "Cancel"
|
64
|
+
|
65
|
+
7. You can print user locale or available locales:
|
66
|
+
|
67
|
+
"Your locale: " + r18n.locale.title
|
68
|
+
"Select another: " + r18n.available_locales.map { |i| i.title }.join(', ')
|
65
69
|
|
66
70
|
== License
|
71
|
+
|
67
72
|
R18n is licensed under the GNU Lesser General Public License version 3.
|
68
73
|
You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
|
69
74
|
|
70
75
|
== Author
|
76
|
+
|
71
77
|
Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
data/lib/r18n-desktop.rb
CHANGED
@@ -35,12 +35,36 @@ end
|
|
35
35
|
module R18n
|
36
36
|
class << self
|
37
37
|
# Get user locale from system environment and load I18n object with locale
|
38
|
-
# information and translations from +
|
39
|
-
# +manual+ put it as last argument.
|
40
|
-
def from_env(
|
38
|
+
# information and translations from +translations_places+. If user set
|
39
|
+
# locale +manual+ put it as last argument.
|
40
|
+
def from_env(translations_places = nil, manual = nil)
|
41
41
|
locales = Array(R18n::I18n.system_locale)
|
42
42
|
locales.insert(0, manual) if not manual.nil?
|
43
|
-
self.set I18n.new(locales,
|
43
|
+
self.set I18n.new(locales, translations_places)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Useful aliases. Set I18n object before use them:
|
48
|
+
#
|
49
|
+
# R18n.from_env('./i18n/')
|
50
|
+
#
|
51
|
+
# t.ok #=> "OK"
|
52
|
+
# l Time.now, :human #=> "now"
|
53
|
+
module Helpers
|
54
|
+
# Get current I18n object.
|
55
|
+
def r18n
|
56
|
+
R18n.get
|
57
|
+
end
|
58
|
+
alias i18n r18n
|
59
|
+
|
60
|
+
# Translate message. Alias for <tt>r18n.t</tt>.
|
61
|
+
def t(*params)
|
62
|
+
R18n.get.t(*params)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Localize object. Alias for <tt>r18n.l</tt>.
|
66
|
+
def l(*params)
|
67
|
+
R18n.get.l(*params)
|
44
68
|
end
|
45
69
|
end
|
46
70
|
end
|
data/spec/r18n-desktop_spec.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
3
|
|
4
4
|
describe "r18n-desktop" do
|
5
|
+
include R18n::Helpers
|
5
6
|
|
6
7
|
it "should return array of system locales" do
|
7
8
|
locale = R18n::I18n.system_locale
|
@@ -10,14 +11,18 @@ describe "r18n-desktop" do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should load I18n from system environment" do
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
R18n.from_env('')
|
15
|
+
r18n.class.should == R18n::I18n
|
16
|
+
r18n.locale.should_not be_empty if String == r18n.locale.class
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
R18n.from_env('', 'en')
|
19
|
+
r18n.locale.should == R18n::Locale.load('en')
|
20
|
+
|
21
|
+
R18n.get.should == r18n
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should add helpers" do
|
19
25
|
|
20
|
-
R18n.get.should == i18n
|
21
26
|
end
|
22
27
|
|
23
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-desktop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey "A.I." Sitnik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-03 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,9 +20,9 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: "0.4"
|
24
24
|
version:
|
25
|
-
description: " A tool to translate your desktop application in several languages.\n It is just a
|
25
|
+
description: " A i18n tool to translate your desktop application in several languages.\n It is just a wrapper for R18n core library.\n It has nice Ruby-style syntax, filters, flexible locales, custom loaders,\n translation support for any classes, time and number localization, several\n user language support, agnostic core package with out-of-box support for\n Rails, Sinatra, Merb and desktop applications.\n"
|
26
26
|
email: andrey@sitnik.ru
|
27
27
|
executables: []
|
28
28
|
|
@@ -65,7 +65,7 @@ rubyforge_project: r18n-desktop
|
|
65
65
|
rubygems_version: 1.3.5
|
66
66
|
signing_key:
|
67
67
|
specification_version: 3
|
68
|
-
summary: A tool to translate your Ruby desktop application.
|
68
|
+
summary: A i18n tool to translate your Ruby desktop application.
|
69
69
|
test_files:
|
70
70
|
- spec/r18n-desktop_spec.rb
|
71
71
|
- spec/spec_helper.rb
|