sy18nc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sy18nc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michał Darda
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Sy18nc
2
+
3
+ Simple tool to synchronize Rails .ymls with locales.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sy18nc', '~> 0.0.1'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sy18nc
18
+
19
+ ## Auto mode
20
+
21
+ If you are using this gem with Rails app, you may create an initializer under your `config/initializers` named `sy18nc.rb`
22
+
23
+ This command will create it for you:
24
+
25
+ $ rails generate sy18nc:install
26
+
27
+ Sample initializer looks like this
28
+
29
+ ```ruby
30
+ Sy18nc.configure do |c|
31
+ c.base_locale = "en"
32
+ c.locales_dir = "config/locales/"
33
+ c.locales = ["de", "es", "fr", "pl"]
34
+ c.files = ["application", "devise", "doorkeeper"]
35
+ end
36
+ ```
37
+
38
+ `base_locale` - your base locale, the rest of locales will be synchronized to this one (`en` by default).
39
+
40
+ `locales_dir` - path to your .ymls with locales (`config/locales` by default).
41
+
42
+ `locales` - the rest of your locales which you would like to keep in sync with the base one.
43
+
44
+ `files` - all the files you want to keep in sync with the base one.
45
+
46
+ `backup` - will save synchronized locales as `.bak` leaving originals untouched (is set to `false` by default).
47
+
48
+ Then you can execute:
49
+
50
+ $ rake sy18nc
51
+
52
+ It will look for every file in `files` list. For example, for `application` file it will find the `application.en` treating this as base and sync every `application.<lang>` which is listed in `locales` config.
53
+
54
+ ## Manual mode
55
+
56
+ sy18nc config/locales/ en.yml ru.yml
57
+
58
+ Will synchronize the `ru` locale, treating `en` as base.
59
+
60
+ If run with `-b` or `--backup` option it will add the `.bak` extension to the output files instead of modifying original locale files.
61
+
62
+ Example:
63
+
64
+ sy18nc -b config/locales/ en.yml ru.yml
65
+
66
+ or:
67
+
68
+ sy18nc --backup config/locales/ en.yml ru.yml
69
+
70
+ ## Example
71
+
72
+ Lets assume we have two locales:
73
+
74
+ en.yml:
75
+
76
+ en:
77
+ application:
78
+ link1: "Hello"
79
+ link2: "Hello"
80
+
81
+ ru.yml:
82
+
83
+ ru:
84
+ application:
85
+ link1: "привет"
86
+
87
+ Command:
88
+
89
+ sy18nc config/locales/ en.yml ru.yml
90
+
91
+ Will result in:
92
+
93
+ ru:
94
+ application:
95
+ link1: "привет"
96
+ link2: "Hello" # FIXME
97
+
98
+ As you can see, it imported missing locales from base (en.yml in this case) and added useful `# FIXME` notice,
99
+ informing you that there is something missing in this locales and you need to fix it.
100
+
101
+ ## Issues
102
+
103
+ Please post any issues via Github Issues. If you want to contribute, see [Contributing](#contributing).
104
+
105
+ ## Contributing
106
+
107
+ 1. Fork it
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create new Pull Request
112
+
113
+ ## Licence
114
+
115
+ MIT Licence. &copy; 2013 Michał Darda <michaldarda@gmail.com>
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ require_relative "lib/sy18nc"
5
+
6
+ Rake::TestTask.new(:spec) do |t|
7
+ t.libs.push "lib"
8
+ t.test_files = FileList["spec/*_spec.rb"]
9
+ t.verbose = true
10
+ end
11
+
12
+ task default: :spec
13
+
14
+ desc "Open an irb session preloaded with this library"
15
+ task :console do
16
+ sh "irb -rubygems -I lib -I extra -r ./lib/sy18nc.rb"
17
+ end
data/bin/sy18nc ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/sy18nc"
3
+
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: sy18nc [options]"
9
+
10
+ if ARGV.empty?
11
+ puts opts.banner
12
+ end
13
+
14
+ opts.on("-b", "--backup", "Create backup") do |b|
15
+ options[:backup] = b
16
+ end
17
+ end.parse!
18
+
19
+ synchronizer = Sy18nc::Synchronizer.new(*ARGV, options)
20
+ synchronizer.synchronize_all
data/ext/array.rb ADDED
@@ -0,0 +1,34 @@
1
+ class Array
2
+ # Extracts options from a set of arguments. Removes and returns the last
3
+ # element in the array if it's a hash, otherwise returns a blank hash.
4
+ #
5
+ # def options(*args)
6
+ # args.extract_options!
7
+ # end
8
+ #
9
+ # options(1, 2) # => {}
10
+ # options(1, 2, :a => :b) # => {:a=>:b}
11
+ def extract_options!
12
+ if last.is_a?(Hash) && last.extractable_options?
13
+ pop
14
+ else
15
+ {}
16
+ end
17
+ end
18
+
19
+ def append!(val)
20
+ self.each do |v|
21
+ v.append!(val)
22
+ end
23
+
24
+ self
25
+ end
26
+
27
+ def mark_fixme!
28
+ self.each do |v|
29
+ v.mark_fixme!
30
+ end
31
+
32
+ self
33
+ end
34
+ end
data/ext/hash.rb ADDED
@@ -0,0 +1,46 @@
1
+ # borrowed from http://api.rubyonrails.org/, customized for own needs
2
+ class Hash
3
+ # Merge the two nested hashes, if the key is missing,
4
+ # we replace it and deeply mark fixme
5
+ def deep_merge!(other_hash)
6
+ other_hash.each_pair do |other_key, other_value|
7
+ self_value = self[other_key]
8
+ self[other_key] = if self_value.is_a?(Hash) && other_value.is_a?(Hash)
9
+ self_value.deep_merge!(other_value)
10
+ elsif self_value.nil?
11
+ other_value.mark_fixme!
12
+ else
13
+ self_value
14
+ end
15
+ end
16
+ self
17
+ end
18
+
19
+ # Appends the val to the every string in nested hash
20
+ def append!(val)
21
+ self.each_pair do |key, value|
22
+ self[key] = value.append!(val)
23
+ end
24
+
25
+ self
26
+ end
27
+
28
+ # Marks the nested hash values with g FIXME
29
+ # see also mark_fixme! in string
30
+ def mark_fixme!
31
+ self.each_pair do |key, value|
32
+ self[key] = value.mark_fixme!
33
+ end
34
+
35
+ self
36
+ end
37
+
38
+ # By default, only instances of Hash itself are extractable.
39
+ # Subclasses of Hash may implement this method and return
40
+ # true to declare themselves as extractable. If a Hash
41
+ # is extractable, Array#extract_options! pops it from
42
+ # the Array when it is the last element of the Array.
43
+ def extractable_options?
44
+ instance_of?(Hash)
45
+ end
46
+ end
data/ext/object.rb ADDED
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def append!(val)
3
+ self
4
+ end
5
+
6
+ def mark_fixme!
7
+ self
8
+ end
9
+ end
data/ext/string.rb ADDED
@@ -0,0 +1,16 @@
1
+ class String
2
+ def mark_fixme!
3
+ # skip if it is already marked or its an alias
4
+ if self =~ /g FIXME/ || self =~ /\*([a-z]*(\_)?)*/
5
+ return self
6
+ end
7
+
8
+ self.replace("#{self} g FIXME")
9
+ end
10
+
11
+ def append!(val)
12
+ return self if self == ""
13
+
14
+ self.replace("#{self}#{val}")
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Sy18nc
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Creates a Sy18nc initializer."
7
+
8
+ def copy_initializer
9
+ template "sy18nc.rb", "config/initializers/sy18nc.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ Sy18nc.configure do |c|
2
+ c.locales = []
3
+ c.files = []
4
+ end
@@ -0,0 +1,25 @@
1
+ module Sy18nc
2
+ class << self
3
+ attr_accessor :configuration
4
+
5
+ def config
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+ def configure
10
+ yield(config)
11
+ end
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :base_locale, :locales_dir, :files, :locales, :backup
16
+
17
+ def initialize
18
+ @base_locale = "en"
19
+ @locales_dir = "#{Dir.pwd}/config/locales"
20
+ @backup = false
21
+ @locales = []
22
+ @files = []
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,74 @@
1
+ require 'psych'
2
+
3
+ module Sy18nc
4
+ class Locale
5
+ attr_reader :name, :hash
6
+
7
+ def initialize(file)
8
+ @name = File.basename(file,".*")
9
+
10
+ file = replace_fixmes(file)
11
+
12
+ begin
13
+ @hash = YAML.load(file)
14
+ rescue Exception => e
15
+ puts "Problem with parsing #{name}, check if this is a valid YAML file http://yamllint.com/."
16
+ puts e.message
17
+ return
18
+ end
19
+
20
+ # little hack
21
+ # force double-quotes everywhere
22
+ hash.append!("foo \nbar")
23
+ end
24
+
25
+ def synchronizable?
26
+ !!hash
27
+ end
28
+
29
+ def body
30
+ hash[hash.keys.first]
31
+ end
32
+
33
+ def synchronize(other)
34
+ body.deep_merge!(other.body)
35
+ end
36
+
37
+ def to_yaml
38
+ # disable line wrap
39
+ yaml = YAML.dump(hash, line_width: -1)
40
+
41
+ # force double quotes in every value
42
+ yaml.gsub!("foo \\nbar","")
43
+ restore_fixmes(yaml)
44
+ end
45
+
46
+ def save(options = {})
47
+ filename = options.fetch(:filename, "#{@name}")
48
+ filename = "#{filename}.yml"
49
+ filename = "#{filename}.bak" if options[:backup]
50
+
51
+ file = File.new(filename, "w+")
52
+ file.write(self.to_yaml)
53
+ file.close
54
+ end
55
+
56
+ # little trick:
57
+ # fetch with the comments
58
+ def replace_fixmes(file)
59
+ file = File.read(File.expand_path(file))
60
+ file.gsub("\' # FIXME", " g FIXME\'")
61
+ .gsub("\" # FIXME", " g FIXME\"")
62
+ .gsub("# FIXME", "g FIXME")
63
+ end
64
+
65
+ # little trick:
66
+ # restore fixmes
67
+ def restore_fixmes(file)
68
+ file.gsub("\sg FIXME\"", "\" # FIXME")
69
+ .gsub("\sg FIXME\'", "\' # FIXME")
70
+ .gsub("g FIXME", "# FIXME")
71
+ .gsub("\"# FIXME\"", "# FIXME")
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ class Sy18ncRailtie < Rails::Railtie
2
+ rake_tasks do
3
+ load "#{File.expand_path(File.dirname(File.dirname(__FILE__)))}/tasks/sy18nc.rake"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ module Sy18nc
2
+ class Synchronizer
3
+ def initialize(*files)
4
+ @options = files.extract_options!
5
+ @path, @base, *@locales = files
6
+
7
+ @path = File.expand_path(@path)
8
+
9
+ @base = Locale.new("#{@path}/#{@base}")
10
+
11
+ @locales = @locales.map do |tfile|
12
+ Locale.new("#{@path}/#{tfile}")
13
+ end
14
+ end
15
+
16
+ def synchronize_all
17
+ @locales.each do |locale|
18
+ if locale.synchronizable?
19
+ locale.synchronize(@base)
20
+ locale.save(@options.merge(filename: "#{@path}/#{locale.name}"))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Sy18nc
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sy18nc.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'yaml'
2
+
3
+ require_relative '../ext/string'
4
+ require_relative '../ext/hash'
5
+ require_relative '../ext/array'
6
+ require_relative '../ext/object'
7
+
8
+ require_relative 'sy18nc/version'
9
+ require_relative 'sy18nc/synchronizer'
10
+ require_relative 'sy18nc/locale'
11
+ require_relative 'sy18nc/config'
12
+ require_relative 'sy18nc/railtie' if defined?(Rails)
@@ -0,0 +1,30 @@
1
+ desc "Synchronizes translations according to config in initializer"
2
+ task :sy18nc => :environment do
3
+ options = Sy18nc.config.backup ? {backup: true} : {}
4
+
5
+ # synchronize the main files
6
+ files = [Sy18nc.config.locales_dir]
7
+ files << "#{Sy18nc.config.base_locale}.yml"
8
+ files << Sy18nc.config.locales.map do |l|
9
+ "#{l}.yml"
10
+ end
11
+
12
+ files.flatten!
13
+
14
+ synchronizer = Sy18nc::Synchronizer.new(*files, options)
15
+ synchronizer.synchronize_all
16
+
17
+ # synchronize the rest of files
18
+ Sy18nc.config.files.each do |s|
19
+ files = [Sy18nc.config.locales_dir]
20
+ files << "#{s}.#{Sy18nc.config.base_locale}.yml"
21
+ files << Sy18nc.config.locales.map do |l|
22
+ "#{s}.#{l}.yml"
23
+ end
24
+
25
+ files.flatten!
26
+
27
+ synchronizer = Sy18nc::Synchronizer.new(*files, options)
28
+ synchronizer.synchronize_all
29
+ end
30
+ end
data/spec/ext_spec.rb ADDED
@@ -0,0 +1,149 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Array do
4
+ it "extracts options" do
5
+ a = [1, 2, 3, 4, { option: true, option2: false }]
6
+ a.extract_options!.must_equal({ option: true, option2: false })
7
+ a.must_equal([1,2,3,4])
8
+
9
+ a.extract_options!.must_equal({})
10
+ a.must_equal([1,2,3,4])
11
+ end
12
+
13
+ it "appends" do
14
+ a = ["hello", "world"]
15
+
16
+ a.append!("appended_string")
17
+
18
+ a.must_equal ["helloappended_string", "worldappended_string"]
19
+ end
20
+ end
21
+
22
+ describe Hash do
23
+ before do
24
+ @hash = {
25
+ :key1 => {
26
+ key11: "Hello",
27
+ key12: "Hello"
28
+ },
29
+ :key2 => {
30
+ key21: "Hello",
31
+ key22: {
32
+ key221: "Hello",
33
+ key222: {
34
+ key2221: "Hello",
35
+ key2222: "Hello"
36
+ }
37
+ }
38
+ }
39
+ }
40
+ end
41
+
42
+ it "deep appending the correct string" do
43
+ appended_hash = {
44
+ :key1 => {
45
+ key11: "Helloappended_string",
46
+ key12: "Helloappended_string"
47
+ },
48
+ :key2 => {
49
+ key21: "Helloappended_string",
50
+ key22: {
51
+ key221: "Helloappended_string",
52
+ key222: {
53
+ key2221: "Helloappended_string",
54
+ key2222: "Helloappended_string"
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ @hash.append!("appended_string").must_equal appended_hash
61
+
62
+ hash2 = {
63
+ :key1 => "helloworld",
64
+ :key2 =>
65
+ [
66
+ "hello",
67
+ "world"
68
+ ]
69
+ }
70
+
71
+ appended_hash2 = {
72
+ :key1 => "helloworldappended_string",
73
+ :key2 =>
74
+ [
75
+ "helloappended_string",
76
+ "worldappended_string"
77
+ ]
78
+ }
79
+
80
+ hash2.append!("appended_string").must_equal appended_hash2
81
+ end
82
+
83
+ it "deep marks fixme" do
84
+ fixme_hash = {
85
+ :key1 => {
86
+ key11: "Hello g FIXME",
87
+ key12: "Hello g FIXME"
88
+ },
89
+ :key2 => {
90
+ key21: "Hello g FIXME",
91
+ key22: {
92
+ key221: "Hello g FIXME",
93
+ key222: {
94
+ key2221: "Hello g FIXME",
95
+ key2222: "Hello g FIXME"
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ @hash.mark_fixme!
102
+ @hash.must_equal fixme_hash
103
+ end
104
+
105
+ it "deep merges and marks fixme" do
106
+ other_hash = {
107
+ :key1 => {
108
+ key11: "Hello",
109
+ },
110
+ :key2 => {
111
+ key22: {
112
+ key221: "Hello"
113
+ }
114
+ }
115
+ }
116
+
117
+ result = {
118
+ :key1 => {
119
+ key11: "Hello",
120
+ key12: "Hello g FIXME"
121
+ },
122
+ :key2 => {
123
+ key21: "Hello g FIXME",
124
+ key22: {
125
+ key221: "Hello",
126
+ key222: {
127
+ key2221: "Hello g FIXME",
128
+ key2222: "Hello g FIXME"
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ other_hash.deep_merge!(@hash).must_equal result
135
+ end
136
+
137
+ it "deep merges hashes with nested arrays" do
138
+ end
139
+
140
+ describe String do
141
+ it "marks fixme" do
142
+ "Hello".mark_fixme!.must_equal("Hello g FIXME")
143
+
144
+ "Hello g FIXME".mark_fixme!.must_equal("Hello g FIXME")
145
+
146
+ "*hello_world".mark_fixme!.must_equal("*hello_world")
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,67 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ not_found: "not found"
5
+ already_confirmed: "was already confirmed"
6
+ not_locked: "was not locked"
7
+ devise:
8
+ failure:
9
+ already_authenticated: 'Already authenticated.'
10
+ unauthenticated: 'You need to sign in before continuing.'
11
+ unconfirmed: 'You have to confirm your account before continuing.'
12
+ locked: 'Your account is locked.'
13
+ invalid: 'Invalid email or password.'
14
+ invalid_token: 'Invalid authentication token.'
15
+ timeout: 'Your session expired, please sign in again to continue.'
16
+ inactive: 'Your account was not activated yet.'
17
+ sessions:
18
+ signed_in: 'Signed in successfully.'
19
+ signed_out: 'Signed out successfully.'
20
+ passwords:
21
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
22
+ updated: 'Your password was changed successfully. You are now signed in.'
23
+ send_paranoid_instructions: "If your account exists in our userbase, you will receive an email with an instruction how to reset you password."
24
+ confirmations:
25
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
26
+ send_paranoid_instructions: 'If your email exists in our userbase, you will receive an email with an instruction how to activate your account.'
27
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
28
+ registrations:
29
+ nested:
30
+ more_nested:
31
+ range:
32
+ - Current
33
+ - 3 days
34
+ - 7 days
35
+ - 1 month
36
+ - 3 months
37
+ signed_up: 'You have signed up successfully.'
38
+ inactive_signed_up: 'You have signed up successfully, however you were not signed in because your account is %{reason}.'
39
+ updated: 'You updated your account successfully.'
40
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
41
+ unlocks:
42
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
43
+ unlocked: 'Your account was successfully unlocked. You are now signed in.'
44
+ send_paranoid_instructions: 'If your account exists in our userbase, you will receive an email with an instruction how to unlock your account.'
45
+ mailer:
46
+ confirmation_instructions:
47
+ subject: 'Confirmation instructions'
48
+ reset_password_instructions:
49
+ subject: 'Reset password instructions'
50
+ unlock_instructions:
51
+ subject: 'Unlock Instructions'
52
+ website:
53
+ one: "eine Website"
54
+ few: "%{count} Websites"
55
+ many: "%{count} Websites"
56
+ other: "%{count} Websites"
57
+ omniauth_callbacks:
58
+ empty_key:
59
+ success: "Successfully authorized from %{kind} account"
60
+ user:
61
+ failure: "Unexpected Authorization failure, please try again."
62
+ range:
63
+ - Current
64
+ - 3 days
65
+ - 7 days
66
+ - 1 month
67
+ - 3 months
@@ -0,0 +1,35 @@
1
+ tr:
2
+ devise:
3
+ confirmations:
4
+ confirmed: "Hesabınız doğrulandı ve giriş yaptınız."
5
+ send_paranoid_instructions: "Eğer mail adresiniz kullanıcı tabanında mevcutsa, hesabınızı nasıl aktif edeceğinizi anlatan bir mail alacaksınız"
6
+ failure:
7
+ already_authenticated: "Zaten doğrulandı"
8
+ inactive: "Hesabınız henüz aktif değil."
9
+ invalid: "Geçersiz email ya da şifre"
10
+ invalid_token: "Geçersiz doğrulama tokeni"
11
+ locked: "Hesabınız kilitlendi"
12
+ timeout: "Oturum süresi doldu. Devam etmek için lütfen tekrar giriş yapınız"
13
+ unauthenticated: "Devam etmeden önce giriş yapmanız gerekiyor."
14
+ unconfirmed: "Devam edebilmek için hesabınızı doğrulamanız gerek."
15
+ mailer:
16
+ reset_password_instructions:
17
+ subject: "Şifre sıfırlama talimatları"
18
+ unlock_instructions:
19
+ subject: "Bloke açma talimatları"
20
+ omniauth_callbacks:
21
+ success: "Successfully authorized from %{kind} account"
22
+ passwords:
23
+ send_instructions: "Hesap şifrenizi nasıl değiştirebileceğinizi gösteren bir mail alacaksınız."
24
+ send_paranoid_instructions: "Eğer hesabınız kullanıcı tabanımızda mevcutsa, hesap şifrenizi nasıl değiştirebileceğinizi gösteren bir mail alacaksınız."
25
+ updated: "Şifreniz başarılı bir şekilde değiştirildi. Şimdi giriş yaptınız."
26
+ registrations:
27
+ destroyed: "Güle güle! Hesabınız iptal edildi. Umarız yakın zamanda tekrar sizi aramızda görürüz."
28
+ inactive_signed_up: "Başarılı bir şekilde üyelik oluşturdunuz fakat giriş yapamadınız çünkü hesabınız %{reason}"
29
+ sessions:
30
+ signed_in: "Başarılı bir şekilde giriş yapıldı."
31
+ signed_out: "Çıkış yapıldı"
32
+ unlocks:
33
+ send_instructions: "Bir kaç dakika içerisinde hesabınızı nasıl açacağınıza dair mail alacaksınız"
34
+ send_paranoid_instructions: "Eğer hesabınız kullanıcı tabanımızda mevcutsa, bir kaç dakika içerisinde hesabınızı nasıl açacağınıza dair mail alacaksınız"
35
+ unlocked: "Hesabınız başarılı bir şekilde açıldı ve şimdi giriş yaptınız."
@@ -0,0 +1,5 @@
1
+ ---
2
+ en:
3
+ promo:
4
+ link1: Hello
5
+ link2: Hello
@@ -0,0 +1,5 @@
1
+ # FIXME
2
+ en :
3
+ key :
4
+ b :
5
+ c: 'Hello" dffd
@@ -0,0 +1,68 @@
1
+ ---
2
+ tr:
3
+ devise:
4
+ confirmations:
5
+ confirmed: "Hesabınız doğrulandı ve giriş yaptınız."
6
+ send_paranoid_instructions: "Eğer mail adresiniz kullanıcı tabanında mevcutsa, hesabınızı nasıl aktif edeceğinizi anlatan bir mail alacaksınız"
7
+ send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." # FIXME
8
+ failure:
9
+ already_authenticated: "Zaten doğrulandı"
10
+ inactive: "Hesabınız henüz aktif değil."
11
+ invalid: "Geçersiz email ya da şifre"
12
+ invalid_token: "Geçersiz doğrulama tokeni"
13
+ locked: "Hesabınız kilitlendi"
14
+ timeout: "Oturum süresi doldu. Devam etmek için lütfen tekrar giriş yapınız"
15
+ unauthenticated: "Devam etmeden önce giriş yapmanız gerekiyor."
16
+ unconfirmed: "Devam edebilmek için hesabınızı doğrulamanız gerek."
17
+ mailer:
18
+ reset_password_instructions:
19
+ subject: "Şifre sıfırlama talimatları"
20
+ unlock_instructions:
21
+ subject: "Bloke açma talimatları"
22
+ confirmation_instructions:
23
+ subject: "Confirmation instructions" # FIXME
24
+ website:
25
+ one: "eine Website" # FIXME
26
+ few: "%{count} Websites" # FIXME
27
+ many: "%{count} Websites" # FIXME
28
+ other: "%{count} Websites" # FIXME
29
+ omniauth_callbacks:
30
+ success: "Successfully authorized from %{kind} account"
31
+ empty_key:
32
+ user:
33
+ failure: "Unexpected Authorization failure, please try again." # FIXME
34
+ range:
35
+ - "Current" # FIXME
36
+ - "3 days" # FIXME
37
+ - "7 days" # FIXME
38
+ - "1 month" # FIXME
39
+ - "3 months" # FIXME
40
+ passwords:
41
+ send_instructions: "Hesap şifrenizi nasıl değiştirebileceğinizi gösteren bir mail alacaksınız."
42
+ send_paranoid_instructions: "Eğer hesabınız kullanıcı tabanımızda mevcutsa, hesap şifrenizi nasıl değiştirebileceğinizi gösteren bir mail alacaksınız."
43
+ updated: "Şifreniz başarılı bir şekilde değiştirildi. Şimdi giriş yaptınız."
44
+ registrations:
45
+ destroyed: "Güle güle! Hesabınız iptal edildi. Umarız yakın zamanda tekrar sizi aramızda görürüz."
46
+ inactive_signed_up: "Başarılı bir şekilde üyelik oluşturdunuz fakat giriş yapamadınız çünkü hesabınız %{reason}"
47
+ nested:
48
+ more_nested:
49
+ range:
50
+ - "Current" # FIXME
51
+ - "3 days" # FIXME
52
+ - "7 days" # FIXME
53
+ - "1 month" # FIXME
54
+ - "3 months" # FIXME
55
+ signed_up: "You have signed up successfully." # FIXME
56
+ updated: "You updated your account successfully." # FIXME
57
+ sessions:
58
+ signed_in: "Başarılı bir şekilde giriş yapıldı."
59
+ signed_out: "Çıkış yapıldı"
60
+ unlocks:
61
+ send_instructions: "Bir kaç dakika içerisinde hesabınızı nasıl açacağınıza dair mail alacaksınız"
62
+ send_paranoid_instructions: "Eğer hesabınız kullanıcı tabanımızda mevcutsa, bir kaç dakika içerisinde hesabınızı nasıl açacağınıza dair mail alacaksınız"
63
+ unlocked: "Hesabınız başarılı bir şekilde açıldı ve şimdi giriş yaptınız."
64
+ errors:
65
+ messages:
66
+ not_found: "not found" # FIXME
67
+ already_confirmed: "was already confirmed" # FIXME
68
+ not_locked: "was not locked" # FIXME
@@ -0,0 +1,4 @@
1
+ ---
2
+ ru:
3
+ promo:
4
+ link1: Birbevoon
@@ -0,0 +1,91 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Sy18nc::Locale do
4
+ before do
5
+ @locale = Sy18nc::Locale.new("spec/fixtures/en.yml")
6
+ end
7
+
8
+ it "loads the yaml" do
9
+ @locale.hash.wont_be_empty
10
+ @locale.hash.must_be_kind_of Hash
11
+
12
+ locale = Sy18nc::Locale.new("spec/fixtures/devise.tr.yml")
13
+ locale.hash.wont_be_empty
14
+ locale.hash.must_be_kind_of Hash
15
+ assert locale.synchronizable?
16
+ end
17
+
18
+ it "is not synchronizable when YAML is not valid" do
19
+ t = Sy18nc::Locale.new("spec/fixtures/not_valid.yml")
20
+ refute t.synchronizable?
21
+ end
22
+
23
+ it "fetches the locale body" do
24
+ @locale.body.wont_equal "en"
25
+ @locale.body.must_be_kind_of Hash
26
+
27
+ locale = Sy18nc::Locale.new("spec/fixtures/devise.tr.yml")
28
+ locale.body.wont_be_empty
29
+ locale.body.must_be_kind_of Hash
30
+ end
31
+
32
+ it "writes the locale to file" do
33
+ refute File.exists?("en.yml")
34
+ @locale.save
35
+ assert File.exists?("en.yml")
36
+
37
+ refute File.exists?("en.yml.bak")
38
+ @locale.save(backup: true)
39
+ assert File.exists?("en.yml.bak")
40
+
41
+ refute File.exists?("locale_file.yml")
42
+ @locale.save(filename: "locale_file")
43
+ assert File.exists?("locale_file.yml")
44
+
45
+ refute File.exists?("locale_file.yml.bak")
46
+ @locale.save(filename: "locale_file", backup: true)
47
+ assert File.exists?("locale_file.yml.bak")
48
+
49
+ cleanup
50
+ end
51
+
52
+ it "converts locale to yml" do
53
+ @locale.to_yaml.wont_be_empty
54
+ @locale.to_yaml.must_be_kind_of String
55
+ @locale.to_yaml.must_equal %q[---
56
+ en:
57
+ promo:
58
+ link1: "Hello"
59
+ link2: "Hello"
60
+ ]
61
+ end
62
+
63
+ it "synchronizes locales" do
64
+ russian_locale = Sy18nc::Locale.new("spec/fixtures/ru.yml")
65
+ russian_locale.synchronize(@locale)
66
+ russian_locale.to_yaml.must_equal %q[---
67
+ ru:
68
+ promo:
69
+ link1: "Birbevoon"
70
+ link2: "Hello" # FIXME
71
+ ]
72
+ @locale.to_yaml.lines.count.must_equal russian_locale.to_yaml.lines.count
73
+
74
+ devise_en = Sy18nc::Locale.new("spec/fixtures/devise.en.yml")
75
+ devise_tr = Sy18nc::Locale.new("spec/fixtures/devise.tr.yml")
76
+ devise_en.to_yaml.lines.count.wont_equal devise_tr.to_yaml.lines.count
77
+
78
+ devise_tr.synchronize(devise_en)
79
+ devise_tr.to_yaml.lines.count.must_equal devise_en.to_yaml.lines.count
80
+ devise_tr.to_yaml.must_equal(File.read(File.expand_path("spec/fixtures/results/devise.tr.yml")))
81
+
82
+
83
+ end
84
+
85
+ def cleanup
86
+ %x[rm en.yml]
87
+ %x[rm en.yml.bak]
88
+ %x[rm locale_file.yml]
89
+ %x[rm locale_file.yml.bak]
90
+ end
91
+ end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
4
+ require 'minitest/autorun'
5
+ require 'minitest/spec'
6
+ require 'turn/autorun'
7
+
8
+ require_relative '../lib/sy18nc.rb'
@@ -0,0 +1,24 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe Sy18nc do
4
+ it "is configurable" do
5
+ Sy18nc.config.base_locale.must_equal "en"
6
+ Sy18nc.config.locales_dir.must_equal "#{Dir.pwd}/config/locales"
7
+ Sy18nc.config.files.must_equal []
8
+ Sy18nc.config.locales.must_equal []
9
+
10
+ Sy18nc.configure do |c|
11
+ c.base_locale = "ru"
12
+ c.locales_dir = "spec/fixtures"
13
+ c.backup = true
14
+ c.files = ["code", "devise", "doorkeeper"]
15
+ c.locales = ["en", "es", "fr", "de"]
16
+ end
17
+
18
+ Sy18nc.config.base_locale.must_equal "ru"
19
+ Sy18nc.config.locales_dir.must_equal "spec/fixtures"
20
+ Sy18nc.config.backup.must_equal true
21
+ Sy18nc.config.files.must_equal ["code", "devise", "doorkeeper"]
22
+ Sy18nc.config.locales.must_equal ["en", "es", "fr", "de"]
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Sy18nc::Synchronizer do
4
+ def setup
5
+ @synchronizer = Sy18nc::Synchronizer.new("spec/fixtures/", "en.yml" ,"ru.yml", backup: true)
6
+ end
7
+
8
+ def teardown
9
+ %x[rm spec/fixtures/*.bak]
10
+ end
11
+
12
+ it "never touches the original translation" do
13
+ before = File.read(File.expand_path("spec/fixtures/en.yml"))
14
+
15
+ synchronizer = Sy18nc::Synchronizer.new("spec/fixtures/", "en.yml" ,"ru.yml", backup: true)
16
+ synchronizer.synchronize_all
17
+ after = File.read(File.expand_path("spec/fixtures/en.yml"))
18
+
19
+ after.must_equal before
20
+ end
21
+
22
+ it "synchronizes translation only once" do
23
+ 3.times do
24
+ @synchronizer.synchronize_all
25
+ File.read(File.expand_path("spec/fixtures/ru.yml.bak")).must_equal %q[---
26
+ ru:
27
+ promo:
28
+ link1: "Birbevoon"
29
+ link2: "Hello" # FIXME
30
+ ]
31
+ end
32
+
33
+ 4.times do
34
+ synchronizer = Sy18nc::Synchronizer.new("spec/fixtures/", "devise.en.yml", "devise.tr.yml", backup: true)
35
+ synchronizer.synchronize_all
36
+ File.read(File.expand_path("spec/fixtures/devise.tr.yml.bak")).must_equal(File.read(File.expand_path("spec/fixtures/results/devise.tr.yml")))
37
+ end
38
+ end
39
+
40
+ it "when backup option is set to true saves as a backup file and does not modify original files" do
41
+ refute File.exists?(File.expand_path("spec/fixtures/ru.yml.bak"))
42
+ @synchronizer.synchronize_all
43
+ assert File.exists?(File.expand_path("spec/fixtures/ru.yml.bak"))
44
+ File.read(File.expand_path("spec/fixtures/ru.yml.bak")).must_equal %q[---
45
+ ru:
46
+ promo:
47
+ link1: "Birbevoon"
48
+ link2: "Hello" # FIXME
49
+ ]
50
+
51
+ refute File.exists?(File.expand_path("spec/fixtures/devise.tr.yml.bak"))
52
+ synchronizer = Sy18nc::Synchronizer.new("spec/fixtures/", "devise.en.yml", "devise.tr.yml", backup: true)
53
+ synchronizer.synchronize_all
54
+ assert File.exists?(File.expand_path("spec/fixtures/devise.tr.yml.bak"))
55
+ File.read(File.expand_path("spec/fixtures/devise.tr.yml.bak")).must_equal(File.read(File.expand_path("spec/fixtures/results/devise.tr.yml")))
56
+ end
57
+ end
data/sy18nc.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sy18nc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sy18nc"
8
+ spec.version = Sy18nc::VERSION
9
+ spec.authors = ["Michał Darda"]
10
+ spec.email = ["michaldarda@gmail.com"]
11
+ spec.description = %q{ Simple tool to synchronize Rails ymls with locales. }
12
+ spec.summary = %q{ Simple tool to synchronize Rails ymls with locales. }
13
+ spec.homepage = "https://github.com/michaldarda/sy18nc"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "psych", "~> 2.0.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "turn", "~> 0.9.6"
26
+ spec.add_development_dependency "simplecov", "~> 0.7.1"
27
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sy18nc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michał Darda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: psych
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: turn
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.6
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.6
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.7.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.7.1
94
+ description: ! ' Simple tool to synchronize Rails ymls with locales. '
95
+ email:
96
+ - michaldarda@gmail.com
97
+ executables:
98
+ - sy18nc
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/sy18nc
108
+ - ext/array.rb
109
+ - ext/hash.rb
110
+ - ext/object.rb
111
+ - ext/string.rb
112
+ - lib/generators/sy18nc/install_generator.rb
113
+ - lib/generators/templates/sy18nc.rb
114
+ - lib/sy18nc.rb
115
+ - lib/sy18nc/config.rb
116
+ - lib/sy18nc/locale.rb
117
+ - lib/sy18nc/railtie.rb
118
+ - lib/sy18nc/synchronizer.rb
119
+ - lib/sy18nc/version.rb
120
+ - lib/tasks/sy18nc.rake
121
+ - spec/ext_spec.rb
122
+ - spec/fixtures/devise.en.yml
123
+ - spec/fixtures/devise.tr.yml
124
+ - spec/fixtures/en.yml
125
+ - spec/fixtures/not_valid.yml
126
+ - spec/fixtures/results/devise.tr.yml
127
+ - spec/fixtures/ru.yml
128
+ - spec/locale_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/sy18nc_spec.rb
131
+ - spec/sychronizer_spec.rb
132
+ - sy18nc.gemspec
133
+ homepage: https://github.com/michaldarda/sy18nc
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.23
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: Simple tool to synchronize Rails ymls with locales.
158
+ test_files:
159
+ - spec/ext_spec.rb
160
+ - spec/fixtures/devise.en.yml
161
+ - spec/fixtures/devise.tr.yml
162
+ - spec/fixtures/en.yml
163
+ - spec/fixtures/not_valid.yml
164
+ - spec/fixtures/results/devise.tr.yml
165
+ - spec/fixtures/ru.yml
166
+ - spec/locale_spec.rb
167
+ - spec/spec_helper.rb
168
+ - spec/sy18nc_spec.rb
169
+ - spec/sychronizer_spec.rb