jekyll-gettext-plugin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d3d292cf009ec4387d1337d7903f914d61720bf2
4
+ data.tar.gz: ddb1256b89b00ed331c8ece5d781dcce19c9a9a4
5
+ SHA512:
6
+ metadata.gz: 503c986408329d0dad2582c59a5b0b1e9ff3d408076bbf5a34680182e773df8310429f454a1b6f7747ceba053753ed359e9f67b81d1a5ca9dab99d6c41aa919c
7
+ data.tar.gz: 63c24f2ce739e37af085419807834a01cd1debcf1247c799e1f4f88fea1dd80a54782795deee8b35e93785dd2acc19c97869e37be9fbb4d9cf5ebe8df742d294
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-gettext-plugin.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Lucas Doyle
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,31 @@
1
+ # Jekyll::Gettext::Plugin
2
+
3
+ A quick and dirty i18n plugin for jekyll based on gettext and po files
4
+
5
+ Inspiration taken from [jekyll-multiple-languages-plugin](https://github.com/screeninteraction/jekyll-multiple-languages-plugin), it was just a little overkill for my needs and I wasn't a fan of managing translations in yaml files.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'jekyll-gettext-plugin'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jekyll-gettext-plugin
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( http://github.com/<my-github-username>/jekyll-gettext-plugin/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/gettext/plugin/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-gettext-plugin"
8
+ spec.version = Jekyll::Gettext::Plugin::VERSION
9
+ spec.authors = ["Lucas Doyle"]
10
+ spec.email = ["lucas.p.doyle@gmail.com"]
11
+ spec.summary = %q{A quick and dirty i18n plugin for jekyll based on gettext and po files}
12
+ spec.homepage = "https://github.com/Stonelinks/jekyll-gettext-plugin"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "fast_gettext", "~> 0.8"
21
+ spec.add_runtime_dependency "get_pomo", "~> 0.6"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,88 @@
1
+ require "jekyll/gettext/plugin/version"
2
+
3
+ require 'fast_gettext'
4
+ require 'get_pomo'
5
+
6
+ # require 'pry'
7
+
8
+ module Jekyll
9
+ class Site
10
+
11
+ alias :process_org :process
12
+ def process
13
+ if !self.config['baseurl']
14
+ self.config['baseurl'] = ""
15
+ end
16
+
17
+ # variables
18
+ config['baseurl_root'] = self.config['baseurl']
19
+ baseurl_org = self.config['baseurl']
20
+ languages = self.config['languages']
21
+ dest_org = self.dest
22
+
23
+ # loop
24
+ self.config['lang'] = languages.first
25
+ self.load_translations
26
+ puts
27
+ puts "Building site for default language: \"#{self.config['lang']}\" to: " + self.dest
28
+ process_org
29
+ languages.drop(1).each do |lang|
30
+
31
+ # build site for language lang
32
+ self.dest = self.dest + "/" + lang
33
+ self.config['baseurl'] = self.config['baseurl'] + "/" + lang
34
+ self.config['lang'] = lang
35
+ self.load_translations
36
+ puts "Building site for language: \"#{self.config['lang']}\" to: " + self.dest
37
+ process_org
38
+
39
+ # reset variables for next language
40
+ self.dest = dest_org
41
+ self.config['baseurl'] = baseurl_org
42
+ end
43
+ puts 'Build complete'
44
+ end
45
+
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
+ def load_translations
52
+ FastGettext.add_text_domain(self.config['lang'], :path => self.source + "/_i18n", :type => :po)
53
+ FastGettext.text_domain = self.config['lang']
54
+ FastGettext.locale = self.config['lang']
55
+ end
56
+ end
57
+
58
+ class LocalizeTag < Liquid::Tag
59
+ include FastGettext::Translation
60
+
61
+ def initialize(tag_name, key, tokens)
62
+ super
63
+ @key = key.strip
64
+ end
65
+
66
+ def render(context)
67
+ if "#{context[@key]}" != "" # check for page variable
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']
77
+
78
+ if candidate == key and lang != 'en'
79
+ puts "Missing i18n key: " + lang + ":" + key
80
+ "*" + lang + ":" + key + "*"
81
+ end
82
+ candidate
83
+ end
84
+ end
85
+ end
86
+
87
+ Liquid::Template.register_tag('t', Jekyll::LocalizeTag)
88
+ Liquid::Template.register_tag('translate', Jekyll::LocalizeTag)
@@ -0,0 +1,7 @@
1
+ module Jekyll
2
+ module Gettext
3
+ module Plugin
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-gettext-plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Doyle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fast_gettext
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: get_pomo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - lucas.p.doyle@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - jekyll-gettext-plugin.gemspec
97
+ - lib/jekyll/gettext/plugin.rb
98
+ - lib/jekyll/gettext/plugin/version.rb
99
+ homepage: https://github.com/Stonelinks/jekyll-gettext-plugin
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: A quick and dirty i18n plugin for jekyll based on gettext and po files
123
+ test_files: []