jekyll-translations 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 193b4cab49b666311eab24cb81b1ae8c304b4f5b
4
+ data.tar.gz: acce204fa83860d1ea53d12e49240e1754f8f0b5
5
+ SHA512:
6
+ metadata.gz: 06fb12b5f0022d131bca1a2771db68a289c616439e878dcdf0f45f1f60b0d423a5e3ecc1c856de7a7b134060496cfd647715c60259d8125c849e316fcf2b1cd8
7
+ data.tar.gz: d3e94990bce50e346ce0ad1d6b1cd7f7d9d26e5e6354fc3207ea7a547391ff9c25dc62885b00a6177cabe0a198f264388c80bab3f5a4eeaacb8e2c36fb60cfe2
@@ -0,0 +1,7 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {"https://github.com/researchsquare/jekyll-translations"}
4
+
5
+ # Specify your gem's dependencies in jekyll-translations.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ # Jekyll::Translations
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jekyll/translations`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jekyll-translations'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jekyll-translations
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-translations.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll/translations"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "jekyll-translations"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Jordan Dalton"]
5
+ spec.email = ["jordan.dalton@researchsquare.com"]
6
+ spec.require_paths = ["lib"]
7
+ spec.summary = %q{Translation tool for Jekyll}
8
+ spec.homepage = "https://github.com/researchsquare/jekyll-translations"
9
+ spec.license = "MIT"
10
+ spec.files = `git ls-files -z`.split("\x0")
11
+ end
@@ -0,0 +1 @@
1
+ require 'jekyll/translations'
@@ -0,0 +1,81 @@
1
+ module Jekyll
2
+ require 'json'
3
+ require 'open-uri'
4
+
5
+ module Translations
6
+ class Generator < Jekyll::Generator
7
+ def generate(site)
8
+ translation_source = site.config['translations']['source']
9
+
10
+ site.data['translations'] = JSON.parse(open(translation_source).read)
11
+ end
12
+ end
13
+
14
+ module TranslateFilter
15
+ @translations = []
16
+ @localizationContext = nil
17
+ @skipTranslationCheck = nil
18
+ @debug_translations = false
19
+
20
+ def translations
21
+ return @translations if @translations
22
+
23
+ site = @context.registers[:site]
24
+ config = site.config['translations']
25
+ @skipTranslationCheck = config['skipTranslationCheck']
26
+ @debug_translations = !@skipTranslationCheck and ENV['DEBUG_TRANSLATIONS'].to_i === 1
27
+
28
+ translation_data = site.data['translations']
29
+ translations = translation_data['common']
30
+
31
+ if config['context'] and translation_data[config['context']]
32
+ translations = translations.merge(translation_data[config['context']])
33
+ end
34
+
35
+ return translations
36
+ end
37
+
38
+ def translate_array(array)
39
+ translated_hash = Hash.new
40
+ array.each { |item| translated_hash[item] = self.t(item) }
41
+
42
+ return translated_hash
43
+ end
44
+
45
+ def t(text, args = [])
46
+ # If we've an array, translate each item and return
47
+ return self.translate_array(text) if text.kind_of?(Array)
48
+
49
+ @translations = self.translations
50
+
51
+ # Uncomment the following block to see a list of items missing translations
52
+ # if @translations[text].nil?
53
+ # puts text.to_json + "\n"
54
+ # end
55
+
56
+ # Fail tests in CircleCI if we don't have translations
57
+ if ENV['CIRCLECI'] and text and @translations[text].nil?
58
+ unless @context.environments.first['page']['skip_translation_check'] or @skipTranslationCheck
59
+ raise Exception.new("Translation not found for: #{text}")
60
+ end
61
+ end
62
+
63
+ if text and @translations[text].nil?
64
+ return @debug_translations ? "<span style='color:red !important;'>#{text}</span>" : text
65
+ end
66
+
67
+ # Cast our stuff to strings to ensure the % operator works as expected below
68
+ if args.kind_of?(Array)
69
+ args = args.map { |arg| arg.to_s }
70
+ else
71
+ args = args.to_s
72
+ end
73
+
74
+ return (@translations[text] % args) if not args.empty?
75
+ return @translations[text]
76
+ end
77
+ end
78
+ end
79
+
80
+ Liquid::Template.register_filter(Translations::TranslateFilter)
81
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-translations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Dalton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - jordan.dalton@researchsquare.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - README.md
23
+ - bin/console
24
+ - bin/setup
25
+ - jekyll-translations.gemspec
26
+ - lib/jekyll-translations.rb
27
+ - lib/jekyll/translations.rb
28
+ homepage: https://github.com/researchsquare/jekyll-translations
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.6.14
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Translation tool for Jekyll
52
+ test_files: []