ixtlan-gettext 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -27,7 +27,7 @@ module Ixtlan
|
|
|
27
27
|
|
|
28
28
|
def crawl
|
|
29
29
|
keys.clear
|
|
30
|
-
Dir[File.join('app', '
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def self.doit(lang)
|
|
36
|
-
l = new(lang)
|
|
37
|
-
l.crawl
|
|
38
|
-
l.dump
|
|
39
|
-
end
|
|
39
|
+
|
|
40
|
+
private
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
#
|
|
1
|
+
# -*- mode: ruby -*-
|
|
2
|
+
|
|
3
|
+
require 'ixtlan/gettext/crawler'
|
|
4
|
+
|
|
2
5
|
namespace :ixtlan do
|
|
3
6
|
|
|
4
|
-
namespace :
|
|
5
|
-
desc 'crawls the local filesystem for _(...) method calls and
|
|
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
|
-
|
|
8
|
-
|
|
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.
|
|
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.
|
|
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:
|
|
4
|
+
hash: 31
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
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:
|
|
18
|
+
date: 2013-01-16 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: ixtlan-remote
|