translate-rails3-plus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ <%= t(:'category_html_erb.key1') %>
@@ -0,0 +1,5 @@
1
+ <script>
2
+ document.createElement('li');
3
+ </script>
4
+
5
+ <%= t(:'category_rhtml.key1') %>
@@ -0,0 +1 @@
1
+ I18n.t('js.alert')
data/spec/keys_spec.rb ADDED
@@ -0,0 +1,179 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Translate::Keys do
5
+ before(:each) do
6
+ I18n.stub!(:default_locale).and_return(:en)
7
+ @keys = Translate::Keys.new
8
+ Translate::Storage.stub!(:root_dir).and_return(i18n_files_dir)
9
+ end
10
+
11
+ describe "to_a" do
12
+ it "extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files" do
13
+ @keys.to_a.map(&:to_s).sort.should == ['article.key1', 'article.key2', 'article.key3', 'article.key4', 'article.key5',
14
+ 'category_erb.key1', 'category_html_erb.key1', 'category_rhtml.key1', 'js.alert']
15
+ end
16
+ end
17
+
18
+ describe "to_hash" do
19
+ it "return a hash with I18n keys and file lists" do
20
+ @keys.to_hash[:'article.key3'].should == ["vendor/plugins/translate/spec/files/translate/app/models/article.rb"]
21
+ end
22
+ end
23
+
24
+ describe "i18n_keys" do
25
+ before(:each) do
26
+ I18n.backend.send(:init_translations) unless I18n.backend.initialized?
27
+ end
28
+
29
+ it "should return all keys in the I18n backend translations hash" do
30
+ I18n.backend.should_receive(:translations).and_return(translations)
31
+ @keys.i18n_keys(:en).should == ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
32
+ end
33
+
34
+ describe "untranslated_keys" do
35
+ before(:each) do
36
+ I18n.backend.stub!(:translations).and_return(translations)
37
+ end
38
+
39
+ it "should return a hash with keys with missing translations in each locale" do
40
+ @keys.untranslated_keys.should == {
41
+ :sv => ['articles.new.page_title', 'categories.flash.created', 'empty']
42
+ }
43
+ end
44
+ end
45
+
46
+ describe "missing_keys" do
47
+ before(:each) do
48
+ @file_path = File.join(i18n_files_dir, "config", "locales", "en.yml")
49
+ Translate::File.new(@file_path).write({
50
+ :en => {
51
+ :home => {
52
+ :page_title => false,
53
+ :intro => {
54
+ :one => "intro one",
55
+ :other => "intro other"
56
+ }
57
+ }
58
+ }
59
+ })
60
+ end
61
+
62
+ after(:each) do
63
+ FileUtils.rm(@file_path)
64
+ end
65
+
66
+ it "should return a hash with keys that are not in the locale file" do
67
+ @keys.stub!(:files).and_return({
68
+ :'home.page_title' => "app/views/home/index.rhtml",
69
+ :'home.intro' => 'app/views/home/index.rhtml',
70
+ :'home.signup' => "app/views/home/_signup.rhtml",
71
+ :'about.index.page_title' => "app/views/about/index.rhtml"
72
+ })
73
+ @keys.missing_keys.should == {
74
+ :'home.signup' => "app/views/home/_signup.rhtml",
75
+ :'about.index.page_title' => "app/views/about/index.rhtml"
76
+ }
77
+ end
78
+ end
79
+
80
+ describe "contains_key?" do
81
+ it "works" do
82
+ hash = {
83
+ :foo => {
84
+ :bar => {
85
+ :baz => false
86
+ }
87
+ }
88
+ }
89
+ Translate::Keys.contains_key?(hash, "").should be_false
90
+ Translate::Keys.contains_key?(hash, "foo").should be_true
91
+ Translate::Keys.contains_key?(hash, "foo.bar").should be_true
92
+ Translate::Keys.contains_key?(hash, "foo.bar.baz").should be_true
93
+ Translate::Keys.contains_key?(hash, :"foo.bar.baz").should be_true
94
+ Translate::Keys.contains_key?(hash, "foo.bar.baz.bla").should be_false
95
+ end
96
+ end
97
+
98
+ describe "translated_locales" do
99
+ before(:each) do
100
+ I18n.stub!(:default_locale).and_return(:en)
101
+ I18n.stub!(:available_locales).and_return([:sv, :no, :en, :root])
102
+ end
103
+
104
+ it "returns all avaiable except :root and the default" do
105
+ Translate::Keys.translated_locales.should == [:sv, :no]
106
+ end
107
+ end
108
+
109
+ describe "to_deep_hash" do
110
+ it "convert shallow hash with dot separated keys to deep hash" do
111
+ Translate::Keys.to_deep_hash(shallow_hash).should == deep_hash
112
+ end
113
+ end
114
+
115
+ describe "to_shallow_hash" do
116
+ it "converts a deep hash to a shallow one" do
117
+ Translate::Keys.to_shallow_hash(deep_hash).should == shallow_hash
118
+ end
119
+ end
120
+
121
+ ##########################################################################
122
+ #
123
+ # Helper Methods
124
+ #
125
+ ##########################################################################
126
+
127
+ def translations
128
+ {
129
+ :en => {
130
+ :home => {
131
+ :about => "This site is about making money"
132
+ },
133
+ :articles => {
134
+ :new => {
135
+ :page_title => "New Article"
136
+ }
137
+ },
138
+ :categories => {
139
+ :flash => {
140
+ :created => "Category created"
141
+ }
142
+ },
143
+ :empty => nil
144
+ },
145
+ :sv => {
146
+ :home => {
147
+ :about => false
148
+ }
149
+ }
150
+ }
151
+ end
152
+ end
153
+
154
+ def shallow_hash
155
+ {
156
+ 'pressrelease.label.one' => "Pressmeddelande",
157
+ 'pressrelease.label.other' => "Pressmeddelanden",
158
+ 'article' => "Artikel",
159
+ 'category' => ''
160
+ }
161
+ end
162
+
163
+ def deep_hash
164
+ {
165
+ :pressrelease => {
166
+ :label => {
167
+ :one => "Pressmeddelande",
168
+ :other => "Pressmeddelanden"
169
+ }
170
+ },
171
+ :article => "Artikel",
172
+ :category => ''
173
+ }
174
+ end
175
+
176
+ def i18n_files_dir
177
+ File.join(ENV['PWD'], "spec", "files", "translate")
178
+ end
179
+ end
data/spec/log_spec.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe Translate::Log do
5
+ describe "write_to_file" do
6
+ before(:each) do
7
+ I18n.locale = :sv
8
+ I18n.backend.store_translations(:sv, from_texts)
9
+ keys = Translate::Keys.new
10
+ @log = Translate::Log.new(:sv, :en, Translate::Keys.to_shallow_hash(from_texts).keys)
11
+ @log.stub!(:file_path).and_return(file_path)
12
+ FileUtils.rm_f file_path
13
+ end
14
+
15
+ after(:each) do
16
+ FileUtils.rm_f file_path
17
+ end
18
+
19
+ it "writes new log file with from texts" do
20
+ File.exists?(file_path).should be_false
21
+ @log.write_to_file
22
+ File.exists?(file_path).should be_true
23
+ Translate::File.new(file_path).read.should == Translate::File.deep_stringify_keys(from_texts)
24
+ end
25
+
26
+ it "merges from texts with current texts in log file and re-writes the log file" do
27
+ @log.write_to_file
28
+ I18n.backend.store_translations(:sv, {:category => "Kategori ny"})
29
+ @log.keys = ['category']
30
+ @log.write_to_file
31
+ Translate::File.new(file_path).read['category'].should == "Kategori ny"
32
+ end
33
+
34
+ def file_path
35
+ File.join(File.dirname(__FILE__), "files", "from_sv_to_en.yml")
36
+ end
37
+
38
+ def from_texts
39
+ {
40
+ :article => {
41
+ :title => "En artikel"
42
+ },
43
+ :category => "Kategori"
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,11 @@
1
+ begin
2
+ # Using PWD here instead of File.dirname(__FILE__) to be able to symlink to plugin
3
+ # from within a Rails app.
4
+ require File.expand_path(ENV['PWD'] + '/../../../spec/spec_helper')
5
+ rescue LoadError => e
6
+ puts "You need to install rspec in your base app\n#{e.message}: #{e.backtrace.join("\n")}"
7
+ exit
8
+ end
9
+
10
+ plugin_spec_dir = File.dirname(__FILE__)
11
+ ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Translate::Storage do
4
+ describe "write_to_file" do
5
+ before(:each) do
6
+ @storage = Translate::Storage.new(:en)
7
+ end
8
+
9
+ it "writes all I18n messages for a locale to YAML file" do
10
+ I18n.backend.should_receive(:translations).and_return(translations)
11
+ @storage.stub!(:file_path).and_return(file_path)
12
+ file = mock(:file)
13
+ file.should_receive(:write).with(translations)
14
+ Translate::File.should_receive(:new).with(file_path).and_return(file)
15
+ @storage.write_to_file
16
+ end
17
+
18
+ def file_path
19
+ File.join(File.dirname(__FILE__), "files", "en.yml")
20
+ end
21
+
22
+ def translations
23
+ {
24
+ :en => {
25
+ :article => {
26
+ :title => "One Article"
27
+ },
28
+ :category => "Category"
29
+ }
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "translate-rails3-plus"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Peter Marklund", "Milan Novota", "Roman Shterenzon", "Garth Smedley"]
12
+ s.date = "2012-07-09"
13
+ s.description = "This plugin provides a web interface for translating Rails I18n texts\n(requires Rails 3.0 or higher) from one locale to another.\nThe plugin has been tested only with the simple I18n backend that ships\nwith Rails.\nI18n texts are read from and written to YAML files under config/locales.\n\nThis gem is a fork of https://github.com/romanbsd/translate.\nFrom the original https://github.com/mynewsdesk/translate\nwhich also includes work from this fork: https://github.com/milann/translate\n"
14
+ s.email = "gsmedley@kanayo.com"
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "app/controllers/translate_controller.rb",
24
+ "app/helpers/translate_helper.rb",
25
+ "app/views/layouts/translate.html.erb",
26
+ "app/views/translate/_array_form.html.erb",
27
+ "app/views/translate/_pagination.html.erb",
28
+ "app/views/translate/_string_form.html.erb",
29
+ "app/views/translate/index.html.erb",
30
+ "config/routes.rb",
31
+ "init.rb",
32
+ "lib/tasks/translate.rake",
33
+ "lib/translate.rb",
34
+ "lib/translate/file.rb",
35
+ "lib/translate/keys.rb",
36
+ "lib/translate/log.rb",
37
+ "lib/translate/routes.rb",
38
+ "lib/translate/storage.rb",
39
+ "spec/controllers/translate_controller_spec.rb",
40
+ "spec/file_spec.rb",
41
+ "spec/files/translate/app/models/article.rb",
42
+ "spec/files/translate/app/views/category.erb",
43
+ "spec/files/translate/app/views/category.html",
44
+ "spec/files/translate/app/views/category.html.erb",
45
+ "spec/files/translate/app/views/category.rhtml",
46
+ "spec/files/translate/public/javascripts/application.js",
47
+ "spec/keys_spec.rb",
48
+ "spec/log_spec.rb",
49
+ "spec/spec_helper.rb",
50
+ "spec/storage_spec.rb",
51
+ "translate-rails3-plus.gemspec"
52
+ ]
53
+ s.homepage = "https://github.com/gsmedley/translate"
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = "1.8.16"
56
+ s.summary = "Newsdesk translate plugin for Rails 3"
57
+
58
+ if s.respond_to? :specification_version then
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<ya2yaml>, ["~> 0.30"])
63
+ else
64
+ s.add_dependency(%q<ya2yaml>, ["~> 0.30"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<ya2yaml>, ["~> 0.30"])
68
+ end
69
+ end
70
+
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translate-rails3-plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Marklund
9
+ - Milan Novota
10
+ - Roman Shterenzon
11
+ - Garth Smedley
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2012-07-09 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: ya2yaml
19
+ requirement: &23168796 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '0.30'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: *23168796
28
+ description: ! 'This plugin provides a web interface for translating Rails I18n texts
29
+
30
+ (requires Rails 3.0 or higher) from one locale to another.
31
+
32
+ The plugin has been tested only with the simple I18n backend that ships
33
+
34
+ with Rails.
35
+
36
+ I18n texts are read from and written to YAML files under config/locales.
37
+
38
+
39
+ This gem is a fork of https://github.com/romanbsd/translate.
40
+
41
+ From the original https://github.com/mynewsdesk/translate
42
+
43
+ which also includes work from this fork: https://github.com/milann/translate
44
+
45
+ '
46
+ email: gsmedley@kanayo.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files:
50
+ - README.md
51
+ files:
52
+ - MIT-LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - VERSION
56
+ - app/controllers/translate_controller.rb
57
+ - app/helpers/translate_helper.rb
58
+ - app/views/layouts/translate.html.erb
59
+ - app/views/translate/_array_form.html.erb
60
+ - app/views/translate/_pagination.html.erb
61
+ - app/views/translate/_string_form.html.erb
62
+ - app/views/translate/index.html.erb
63
+ - config/routes.rb
64
+ - init.rb
65
+ - lib/tasks/translate.rake
66
+ - lib/translate.rb
67
+ - lib/translate/file.rb
68
+ - lib/translate/keys.rb
69
+ - lib/translate/log.rb
70
+ - lib/translate/routes.rb
71
+ - lib/translate/storage.rb
72
+ - spec/controllers/translate_controller_spec.rb
73
+ - spec/file_spec.rb
74
+ - spec/files/translate/app/models/article.rb
75
+ - spec/files/translate/app/views/category.erb
76
+ - spec/files/translate/app/views/category.html
77
+ - spec/files/translate/app/views/category.html.erb
78
+ - spec/files/translate/app/views/category.rhtml
79
+ - spec/files/translate/public/javascripts/application.js
80
+ - spec/keys_spec.rb
81
+ - spec/log_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/storage_spec.rb
84
+ - translate-rails3-plus.gemspec
85
+ homepage: https://github.com/gsmedley/translate
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.16
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Newsdesk translate plugin for Rails 3
109
+ test_files: []