rails-i18nterface 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -10
- data/app/controllers/rails_i18nterface/application_controller.rb +2 -0
- data/app/controllers/rails_i18nterface/translate_controller.rb +29 -80
- data/app/helpers/rails_i18nterface/application_helper.rb +2 -0
- data/app/helpers/rails_i18nterface/translate_helper.rb +2 -0
- data/app/views/rails_i18nterface/translate/index.html.erb +14 -23
- data/config/routes.rb +2 -0
- data/lib/rails-i18nterface.rb +3 -1
- data/lib/rails-i18nterface/cache.rb +40 -0
- data/lib/rails-i18nterface/engine.rb +2 -0
- data/lib/rails-i18nterface/keys.rb +24 -112
- data/lib/rails-i18nterface/sourcefiles.rb +14 -12
- data/lib/rails-i18nterface/storage.rb +2 -4
- data/lib/rails-i18nterface/utils.rb +51 -0
- data/lib/rails-i18nterface/version.rb +3 -1
- data/lib/rails-i18nterface/yamlfile.rb +15 -17
- data/lib/tasks/rails-i18nterface.rake +1 -0
- data/spec/controllers/translate_controller_spec.rb +18 -33
- data/spec/internal/app/controllers/application_controller.rb +2 -0
- data/spec/internal/app/models/article.rb +8 -2
- data/spec/internal/config/routes.rb +2 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/log/test.log +241 -1608
- data/spec/lib/cache_spec.rb +51 -0
- data/spec/lib/keys_spec.rb +59 -88
- data/spec/lib/sourcefiles_spec.rb +8 -6
- data/spec/lib/storage_spec.rb +2 -0
- data/spec/lib/utils_spec.rb +34 -0
- data/spec/lib/yamlfile_spec.rb +10 -5
- data/spec/requests/search_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -3
- metadata +104 -67
- checksums.yaml +0 -7
- data/app/models/rails_i18nterface/translation.rb +0 -23
- data/db/migrate/20110921112044_create_translations.rb +0 -18
- data/db/migrate/20130422115639_rename_translation_to_namespace.rb +0 -8
- data/lib/rails-i18nterface/log.rb +0 -40
- data/spec/lib/log_spec.rb +0 -47
- data/spec/models/translation_spec.rb +0 -9
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: c0e0d7a4246ff44ee6cc0865f2b2bcedb3ebf5fd
|
4
|
-
data.tar.gz: 8faea23f3737fc3ece301d0f153c5a85450cd327
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 9b936cb71327bf12884dbbd9eb6b360ee54a0d3997204b2994f94d446ffedabc1fca32bd7a5dd06af68854ca19435d43d8e1021ba69cb4e11022c6d8d1fad08c
|
7
|
-
data.tar.gz: 7b49046b1b17a6e92efe916f167083274cfeb19c92ff1d500a1806b73463ad08094ee078364812ecb3cb83c93d54448e4673fb6e1ad0e54733fee7593f20ca16
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class RailsI18nterface::Translation < ActiveRecord::Base
|
2
|
-
|
3
|
-
def self.update(locale, keys)
|
4
|
-
keys.each do |k, v|
|
5
|
-
t = RailsI18nterface::Translation.where(key: k, locale: locale).first
|
6
|
-
if t
|
7
|
-
if !v || v == ''
|
8
|
-
t.destroy!
|
9
|
-
next
|
10
|
-
elsif t.value != v
|
11
|
-
t.value = v
|
12
|
-
t.save!
|
13
|
-
end
|
14
|
-
elsif v != ''
|
15
|
-
t = RailsI18nterface::Translation.new
|
16
|
-
t.key = k
|
17
|
-
t.locale = locale
|
18
|
-
t.save!
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateTranslations < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :translations do |t|
|
4
|
-
t.string :locale
|
5
|
-
t.string :key
|
6
|
-
t.text :value
|
7
|
-
t.text :interpolations
|
8
|
-
t.boolean :is_proc, :default => false
|
9
|
-
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.down
|
15
|
-
drop_table :translations
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module RailsI18nterface
|
2
|
-
class Log
|
3
|
-
|
4
|
-
include Utils
|
5
|
-
|
6
|
-
attr_accessor :from_locale, :to_locale, :keys
|
7
|
-
|
8
|
-
def initialize(from_locale, to_locale, keys)
|
9
|
-
self.from_locale = from_locale
|
10
|
-
self.to_locale = to_locale
|
11
|
-
self.keys = keys.reject { |k, v| v == '' }
|
12
|
-
end
|
13
|
-
|
14
|
-
def write_to_file
|
15
|
-
current_texts = File.exists?(file_path) ? file.read : {}
|
16
|
-
current_texts.merge!(from_texts)
|
17
|
-
file.write(remove_blanks(current_texts))
|
18
|
-
end
|
19
|
-
|
20
|
-
def read
|
21
|
-
file.read
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
def file
|
26
|
-
@file ||= Yamlfile.new(file_path)
|
27
|
-
end
|
28
|
-
|
29
|
-
def from_texts
|
30
|
-
file.deep_stringify_keys(Keys.to_deep_hash(keys.reduce({ }) do |hash, key|
|
31
|
-
hash[key] = I18n.backend.send(:lookup, from_locale, key)
|
32
|
-
hash
|
33
|
-
end))
|
34
|
-
end
|
35
|
-
|
36
|
-
def file_path
|
37
|
-
File.join(Rails.root, 'config', 'locales', 'log', "from_#{from_locale}_to_#{to_locale}.yml")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/spec/lib/log_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe RailsI18nterface::Log do
|
4
|
-
describe 'write_to_file' do
|
5
|
-
before(:each) do
|
6
|
-
I18n.locale = :sv
|
7
|
-
I18n.backend.store_translations(:sv, from_texts)
|
8
|
-
#keys = RailsI18nterface::Keys.new
|
9
|
-
@log = RailsI18nterface::Log.new(:sv, :en, RailsI18nterface::Keys.to_shallow_hash(from_texts).keys)
|
10
|
-
@log.stub!(:file_path).and_return(file_path)
|
11
|
-
FileUtils.rm_f file_path
|
12
|
-
end
|
13
|
-
|
14
|
-
after(:each) do
|
15
|
-
FileUtils.rm_f file_path
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'writes new log file with from texts' do
|
19
|
-
File.exists?(file_path).should be_false
|
20
|
-
@log.write_to_file
|
21
|
-
File.exists?(file_path).should be_true
|
22
|
-
expected = RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(from_texts)
|
23
|
-
RailsI18nterface::Yamlfile.new(file_path).read.should == expected
|
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
|
-
RailsI18nterface::Yamlfile.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
|