jekyll-gettext-plugin 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -2
- data/lib/jekyll/gettext/plugin/version.rb +1 -1
- data/lib/jekyll/gettext/plugin.rb +59 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1716d592cfa9aa978f06d9627be07fe01e56e715
|
4
|
+
data.tar.gz: 83179f3b398ab399692bd03a6c42396556b92b70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b3b49c5f887e17f2b253ef5c470ca3baa24736bd840f10cced0d4a22f7c8fef0ed3e35aa9f18bc0cdd4b48d4113a96130ea96309c9e8b22c77839b123c70c12
|
7
|
+
data.tar.gz: ddaeacc634bd6622e39dbe07c8907c77f671316d8afa31f7b4e4e861aac98202e191608a0392a97aa2893fe861f3aab7ce137d2ced0a7ae6f5758436288fd934
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,14 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
- In _config.yml, add a languages array where the first one is your primary language, for example `languages: ["ja", "ja", "en"]`
|
24
|
+
- For each language, make sure there is a po file in `_i18n/<LANG>/<LANG>.po`. So if you're doing japanese translations for the first time you'd do something like `mkdir -p _i18n/ja && touch _i18n/ja/ja.po`
|
25
|
+
- Use tags that look like this {% t hey there! %} in your web pages
|
26
|
+
- Any time jekyll builds, the plugin will add any new keys to the po file. Fill these in and rebuild to see the translated website. Each translated website is served at a url relative to that language, IE `http://localhost:8080/ja/`, `http://localhost:8080/en/`, etc.
|
24
27
|
|
25
28
|
## Contributing
|
26
29
|
|
27
|
-
1. Fork it ( http://github.com
|
30
|
+
1. Fork it ( http://github.com/Stonelinks/jekyll-gettext-plugin/fork )
|
28
31
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
32
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
33
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -3,9 +3,24 @@ require "jekyll/gettext/plugin/version"
|
|
3
3
|
require 'fast_gettext'
|
4
4
|
require 'get_pomo'
|
5
5
|
|
6
|
-
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
class TranslationLogger
|
9
|
+
def initialize
|
10
|
+
@translations = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_translations
|
14
|
+
return @translations
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(unfound)
|
18
|
+
@translations.push(unfound)
|
19
|
+
end
|
20
|
+
end
|
7
21
|
|
8
22
|
module Jekyll
|
23
|
+
|
9
24
|
class Site
|
10
25
|
|
11
26
|
alias :process_org :process
|
@@ -22,19 +37,22 @@ module Jekyll
|
|
22
37
|
|
23
38
|
# loop
|
24
39
|
self.config['lang'] = languages.first
|
25
|
-
self.load_translations
|
26
40
|
puts
|
27
41
|
puts "Building site for default language: \"#{self.config['lang']}\" to: " + self.dest
|
42
|
+
self.load_translations
|
28
43
|
process_org
|
44
|
+
self.save_missing_translations
|
45
|
+
|
29
46
|
languages.drop(1).each do |lang|
|
30
47
|
|
31
48
|
# build site for language lang
|
32
49
|
self.dest = self.dest + "/" + lang
|
33
50
|
self.config['baseurl'] = self.config['baseurl'] + "/" + lang
|
34
51
|
self.config['lang'] = lang
|
35
|
-
self.load_translations
|
36
52
|
puts "Building site for language: \"#{self.config['lang']}\" to: " + self.dest
|
53
|
+
self.load_translations
|
37
54
|
process_org
|
55
|
+
self.save_missing_translations
|
38
56
|
|
39
57
|
# reset variables for next language
|
40
58
|
self.dest = dest_org
|
@@ -43,16 +61,45 @@ module Jekyll
|
|
43
61
|
puts 'Build complete'
|
44
62
|
end
|
45
63
|
|
46
|
-
# TODO:
|
47
|
-
# parse the po file and store it in site whenever lang changes
|
48
|
-
# if a key is missing, add it to a list on site object
|
49
|
-
# when site is done processing, write back to po file
|
50
|
-
|
51
64
|
def load_translations
|
52
|
-
|
65
|
+
@all_translations = TranslationLogger.new
|
66
|
+
@missing_translations = TranslationLogger.new
|
67
|
+
|
68
|
+
repos = [
|
69
|
+
FastGettext::TranslationRepository.build(self.config['lang'], :type=>:logger, :callback=>@all_translations),
|
70
|
+
FastGettext::TranslationRepository.build(self.config['lang'], :type=>:logger, :callback=>@missing_translations),
|
71
|
+
FastGettext::TranslationRepository.build(self.config['lang'], :path => self.source + "/_i18n", :type => :po)
|
72
|
+
]
|
73
|
+
FastGettext.add_text_domain(self.config['lang'], :type=>:chain, :chain=>repos)
|
74
|
+
|
53
75
|
FastGettext.text_domain = self.config['lang']
|
54
76
|
FastGettext.locale = self.config['lang']
|
55
77
|
end
|
78
|
+
|
79
|
+
def save_missing_translations
|
80
|
+
filename = self.source + "/_i18n/" + self.config['lang'] + '/' + self.config['lang'] + '.po'
|
81
|
+
existing_translations = GetPomo.unique_translations(GetPomo::PoFile.parse(File.read(filename)))
|
82
|
+
|
83
|
+
# ignores any keys that already exist
|
84
|
+
missing_translations_msgids = @missing_translations.get_translations.reject {|msgid| existing_translations.find {|trans| trans.msgid == msgid}}
|
85
|
+
|
86
|
+
final_translations = existing_translations
|
87
|
+
|
88
|
+
missing_translations_msgids.each do |new_msgid|
|
89
|
+
new_trans = GetPomo::Translation.new
|
90
|
+
new_trans.msgid = new_msgid
|
91
|
+
new_trans.msgstr = ""
|
92
|
+
final_translations.push(new_trans)
|
93
|
+
end
|
94
|
+
|
95
|
+
# uncomment this to remove translations that were not used
|
96
|
+
# not_used = final_translations.reject { |trans| @all_translations.get_translations.find {|msgid| trans.msgid == msgid}}
|
97
|
+
# final_translations = final_translations.reject {|trans1| not_used.find {|trans2| trans1.msgid == trans2.msgid}}
|
98
|
+
|
99
|
+
final_translations.sort_by!(&:msgid)
|
100
|
+
|
101
|
+
File.open(filename, 'w'){|f|f.print(GetPomo::PoFile.to_text(final_translations))}
|
102
|
+
end
|
56
103
|
end
|
57
104
|
|
58
105
|
class LocalizeTag < Liquid::Tag
|
@@ -64,20 +111,10 @@ module Jekyll
|
|
64
111
|
end
|
65
112
|
|
66
113
|
def render(context)
|
67
|
-
|
68
|
-
key = "#{context[@key]}"
|
69
|
-
else
|
70
|
-
key = @key
|
71
|
-
end
|
72
|
-
candidate = _(key)
|
73
|
-
|
74
|
-
# binding.pry
|
75
|
-
|
76
|
-
lang = context.registers[:site].config['lang']
|
114
|
+
candidate = _(@key)
|
77
115
|
|
78
|
-
if candidate ==
|
79
|
-
|
80
|
-
"*" + lang + ":" + key + "*"
|
116
|
+
if candidate == ""
|
117
|
+
candidate = @key
|
81
118
|
end
|
82
119
|
candidate
|
83
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-gettext-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_gettext
|