ixtlan-gettext 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ module Ixtlan
27
27
 
28
28
  def crawl
29
29
  keys.clear
30
- Dir[File.join('app', 'views', '**', '*rb')].each do |f|
30
+ Dir[File.join('app', '**', '*rb')].each do |f|
31
31
  File.read(f).each_line do |line|
32
32
  extract_key(line) if line =~ /_[ (]/
33
33
  end
@@ -58,4 +58,4 @@ module Ixtlan
58
58
  end
59
59
  end
60
60
  end
61
- end
61
+ end
@@ -1,69 +1,61 @@
1
- class NewLocale
2
-
3
- def initialize(lang)
4
- @lang = lang
5
- @file = "config/locales/#{lang}.yml"
6
- @trans = if File.exists? @file
7
- YAML.load_file(@file)[lang]
8
- else
9
- {}
10
- end
11
- end
12
-
13
- def crawl
14
- Dir[File.join('app', 'views', '**/*rb')].each do |f|
15
- File.read(f).each do |line|
16
- extract_key(line) if line =~ /_[ (]/
1
+ #
2
+ # ixtlan_gettext - helper to use fast_gettext with datamapper/ixtlan
3
+ # Copyright (C) 2012 Christian Meier
4
+ #
5
+ # This file is part of ixtlan_gettext.
6
+ #
7
+ # ixtlan_gettext is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as
9
+ # published by the Free Software Foundation, either version 3 of the
10
+ # License, or (at your option) any later version.
11
+ #
12
+ # ixtlan_gettext is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with ixtlan_gettext. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+ module Ixtlan
21
+ module Gettext
22
+ class Crawler
23
+
24
+ def self.crawl
25
+ Crawler.new.crawl
17
26
  end
18
- end
19
- end
20
27
 
21
- def dump
22
- merge
23
- result = {}
24
- result[@lang] = @trans
25
- lines = result.to_yaml.sub(/---\s*\n/, '').gsub(/ -\s*\n/, '').split /\n/
26
- lines.sort!{|n,m| n.sub(/^ /, "zz") <=> m.sub(/^ /, "zz") }
27
- File.open(@file, 'w') do |f|
28
- lines.each do |l|
29
- f.puts l
30
- f.puts " -" if l =~ /^ .*: $/
28
+ def crawl
29
+ keys.clear
30
+ Dir[File.join('app', 'views', '**', '*rb')].each do |f|
31
+ File.read(f).each_line do |line|
32
+ extract_key(line) if line =~ /_[ (]/
33
+ end
34
+ end
35
+ keys.sort!
36
+ keys.uniq!
37
+ keys
31
38
  end
32
- end
33
- end
34
-
35
- def self.doit(lang)
36
- l = new(lang)
37
- l.crawl
38
- l.dump
39
- end
39
+
40
+ private
40
41
 
41
- private
42
-
43
- def merge
44
- keys.each do |k|
45
- @trans[k] = k unless @trans.key? k
46
- end
47
- @trans.keys.each do |k|
48
- @trans[" Deleted-Key-#{k}"] = @trans.delete(k) if !keys.member?(k) && (k =~ /^ Deleted-Key-/).nil?
49
- end
50
- end
51
-
52
- def keys
53
- @keys ||= []
54
- end
55
-
56
- def extract_key(line)
57
- line.gsub!(/_[^ (]/, '-')
58
- extract(line, "'")
59
- extract(line, '"')
60
- end
61
-
62
- def extract(line, sep)
63
- if line =~ /.*_[ (][#{sep}]/
64
- k = line.sub(/[^_]*_[ (][#{sep}]/, '').sub(/[#{sep}].*\n/, '')
65
- keys << k; puts k unless keys.member? k
66
- extract_key(line.sub(/[^_]*_[ (][#{sep}][^#{sep}]+[#{sep}]/, ''))
42
+ def keys
43
+ @keys ||= []
44
+ end
45
+
46
+ def extract_key(line)
47
+ extract(line, "'")
48
+ extract(line, '"')
49
+ end
50
+
51
+ def extract(line, sep)
52
+ if line =~ /.*_[ (][#{sep}]/
53
+ # non-greedy +? and *? vs. greedy + and *
54
+ k = line.sub( /.*?_[ (][#{sep}]/, '').sub(/[#{sep}].*\n/, '')
55
+ keys << k; puts k unless keys.member? k
56
+ extract_key(line.sub(/[^_]*_[ (][#{sep}][^#{sep}]+[#{sep}]/, ''))
57
+ end
58
+ end
67
59
  end
68
60
  end
69
- end
61
+ end
@@ -11,6 +11,7 @@ namespace :ixtlan do
11
11
  puts Ixtlan::Gettext::Crawler.crawl.join( "\n\t" )
12
12
  end
13
13
 
14
+ desc 'crawls the local filesystem for _(...) method calls and sends them'
14
15
  task :update => :environment do
15
16
  puts 'crawling files . . .'
16
17
  data = {:translation_keys => Ixtlan::Gettext::Crawler.crawl }
@@ -20,12 +21,14 @@ namespace :ixtlan do
20
21
  Ixtlan::Gettext::TranslationKey.update_all(keys)
21
22
  end
22
23
 
24
+ desc 'commit the last update, i.e. the keys from last update are the only keys now'
23
25
  task :commit => :environment do
24
26
  keys = Rails.application.config.rest.update(Ixtlan::Gettext::TranslationKey, :commit, nil)
25
27
  puts "updating local database with #{keys.size} keys . . ."
26
28
  Ixtlan::Gettext::TranslationKey.update_all(keys)
27
29
  end
28
30
 
31
+ desc 'rollback the last update, i.e. undo all the changes done by last update'
29
32
  task :rollback => :environment do
30
33
  keys = Rails.application.config.rest.update(Ixtlan::Gettext::TranslationKey, :rollback, nil)
31
34
  puts "updating local database with #{keys.size} keys . . ."
@@ -1,23 +1,37 @@
1
- # --*-- ruby-mode --*--
1
+ # -*- mode: ruby -*-
2
+
3
+ require 'ixtlan/gettext/crawler'
4
+
2
5
  namespace :ixtlan do
3
6
 
4
- namespace :translations do
5
- desc 'crawls the local filesystem for _(...) method calls and sends the collected translation keys to the remote service'
7
+ namespace :gettext do
8
+ desc 'crawls the local filesystem for _(...) method calls and dumps them to the console'
9
+ task :keys => :environment do
10
+ print "\t"
11
+ puts Ixtlan::Gettext::Crawler.crawl.join( "\n\t" )
12
+ end
13
+
6
14
  task :update => :environment do
7
- data = {:translation_keys => ENV['KEYS'].split(/,/)}
8
- keys = Rails.application.config.restserver.update(data)
15
+ puts 'crawling files . . .'
16
+ data = {:translation_keys => Ixtlan::Gettext::Crawler.crawl }
17
+ puts "sending #{data[:translation_keys].size} keys to gettext server . . ."
18
+ keys = Rails.application.config.rest.update(Ixtlan::Gettext::TranslationKey, data)
19
+ puts "updating local database with #{keys.size} keys . . ."
9
20
  Ixtlan::Gettext::TranslationKey.update_all(keys)
10
21
  end
11
22
 
12
23
  task :commit => :environment do
13
- keys = Rails.application.config.restserver.update(:translation_keys, :commit)
24
+ keys = Rails.application.config.rest.update(Ixtlan::Gettext::TranslationKey, :commit, nil)
25
+ puts "updating local database with #{keys.size} keys . . ."
14
26
  Ixtlan::Gettext::TranslationKey.update_all(keys)
15
27
  end
16
28
 
17
29
  task :rollback => :environment do
18
- keys = Rails.application.config.restserver.update(:translation_keys, :rollback)
30
+ keys = Rails.application.config.rest.update(Ixtlan::Gettext::TranslationKey, :rollback, nil)
31
+ puts "updating local database with #{keys.size} keys . . ."
19
32
  Ixtlan::Gettext::TranslationKey.update_all(keys)
20
33
  end
21
34
  end
22
35
 
23
36
  end
37
+ # vim: syntax=Ruby
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ixtlan-gettext
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Meier
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-31 00:00:00 Z
18
+ date: 2013-01-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ixtlan-remote