tools_for_locales 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = ToolsForLocales
2
+
3
+ == Description
4
+
5
+ A small collection of tools for locales wannabe project. Currently supports only sort_tokens.
6
+
7
+ === Sort Tokens
8
+
9
+ When working with lot of tokens it's best practice to arrange the keys in alphabetical order.
10
+ That is what this task does.
11
+
12
+ Give a yaml file like this:
13
+
14
+ en:
15
+ admin:
16
+ menu:
17
+ company: "Company"
18
+ about_us: "About Us"
19
+ flashes:
20
+ success: "Success"
21
+ failure: "Failure"
22
+
23
+ The result will be:
24
+
25
+ en:
26
+ admin:
27
+ flashes:
28
+ failure: "Failure"
29
+ success: "Success"
30
+ menu:
31
+ about_us: "About Us"
32
+ company: "Company"
33
+
34
+ == Install
35
+
36
+ In your Gemfile
37
+
38
+ gem 'tools_for_locales'
39
+
40
+ Currently is tested on rails3+ and ruby 1.9.3
41
+
42
+ == Usage
43
+
44
+ rake tools_for_locales:sort_tokens
45
+
46
+ *WARNING*
47
+ All locale files will be overwritten
48
+
49
+ == Tests
50
+
51
+ rspec spec/
52
+
53
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ToolsForLocales'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,26 @@
1
+ require 'tools_for_locales'
2
+
3
+ namespace :tools_for_locales do
4
+
5
+ desc 'sort tokens in all locales'
6
+ task :sort_tokens do
7
+ require 'yaml'
8
+ include ToolsForLocales
9
+
10
+ Dir["config/locales/**/*.yml"].each do |file|
11
+ puts "processing: #{file}"
12
+ yaml = YAML::load(File.open(file))
13
+ file = File.new(file, "w")
14
+ begin
15
+ file.puts sort_hash(yaml).to_yaml
16
+ file.close
17
+ rescue
18
+ # revert
19
+ puts '>> revert changes'
20
+ file.puts yaml.to_yaml
21
+ file.close
22
+ end
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'tools_for_locales/railtie' if defined?(Rails)
2
+
3
+ module ToolsForLocales
4
+
5
+ def sort_hash(hash)
6
+ hash = Hash[hash.sort]
7
+ hash.inject({}) do |h, (key, value)|
8
+ if value.is_a? Hash
9
+ h[key] = sort_hash(value)
10
+ else
11
+ h[key] = value
12
+ end
13
+ h
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'tools_for_locales'
2
+ require 'rails'
3
+ module ToolsForLocales
4
+ class Railtie < Rails::Railtie
5
+
6
+ rake_tasks do
7
+ load "tasks/tools_for_locales_tasks.rake"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ToolsForLocales
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tools_for_locales
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Giorgos Tsiftsis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A collection of tools for handling locales in a rails project.
15
+ email:
16
+ - giorgos.tsiftsis@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/tools_for_locales.rb
22
+ - lib/tasks/tools_for_locales_tasks.rake
23
+ - lib/tools_for_locales/railtie.rb
24
+ - lib/tools_for_locales/version.rb
25
+ - MIT-LICENSE
26
+ - Rakefile
27
+ - README.rdoc
28
+ homepage: https://github.com/chief/tools_for_locales
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ segments:
41
+ - 0
42
+ hash: 38725277635769607
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ segments:
50
+ - 0
51
+ hash: 38725277635769607
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 1.8.10
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: A collection of tools for handling locales in a rails project.
58
+ test_files: []