jekyll-translations 0.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 193b4cab49b666311eab24cb81b1ae8c304b4f5b
4
- data.tar.gz: acce204fa83860d1ea53d12e49240e1754f8f0b5
2
+ SHA256:
3
+ metadata.gz: 6d67696a7fe385237d6ea65429cc759c40caaae0fc0d04b646405593c792b5b3
4
+ data.tar.gz: 94e6b3251c933d79e524f0515fe277209ab2a5ec540148a0ef32200f659a44ab
5
5
  SHA512:
6
- metadata.gz: 06fb12b5f0022d131bca1a2771db68a289c616439e878dcdf0f45f1f60b0d423a5e3ecc1c856de7a7b134060496cfd647715c60259d8125c849e316fcf2b1cd8
7
- data.tar.gz: d3e94990bce50e346ce0ad1d6b1cd7f7d9d26e5e6354fc3207ea7a547391ff9c25dc62885b00a6177cabe0a198f264388c80bab3f5a4eeaacb8e2c36fb60cfe2
6
+ metadata.gz: cb51ce3fe0b04c37d5b0a32f8bfb836a93abccf53f978935c976da715c6d08b5f4c68aad9b388c2fe6befcb21ecaccddeab79b1753d2ee5207c51b86f6310243
7
+ data.tar.gz: 94404d93696ef1ea6c4b9d54a63f651730a86b6e80f1af1381765ea203320a3d9e6c29c484dee8430f025bedea837041504503ae97bab981acab722f86114cb6
@@ -0,0 +1,55 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+ pull-requests: write
11
+
12
+ jobs:
13
+ release-please:
14
+ runs-on: [ubuntu-latest]
15
+
16
+ steps:
17
+ - name: Release Please
18
+ uses: GoogleCloudPlatform/release-please-action@v3
19
+ id: release
20
+ with:
21
+ release-type: ruby
22
+ package-name: jekyll-translations
23
+ bump-minor-pre-major: true
24
+ version-file: "lib/jekyll/version.rb"
25
+
26
+ outputs:
27
+ release_created: ${{ steps.release.outputs.release_created }}
28
+
29
+ publish-gem:
30
+ runs-on: [ubuntu-latest]
31
+ needs: [release-please]
32
+ if: ${{ needs.release-please.outputs.release_created }}
33
+
34
+ steps:
35
+ - name: Checkout
36
+ uses: actions/checkout@v3
37
+
38
+ - name: Setup Ruby
39
+ uses: ruby/setup-ruby@v1
40
+ with:
41
+ ruby-version: 3.0.0
42
+
43
+ - name: Install the bundle
44
+ run: bundle install
45
+
46
+ - name: publish gem
47
+ env:
48
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
49
+ run: |
50
+ mkdir -p $HOME/.gem
51
+ touch $HOME/.gem/credentials
52
+ chmod 0600 $HOME/.gem/credentials
53
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
54
+ gem build *.gemspec
55
+ gem push *.gem
data/.gitignore CHANGED
@@ -5,3 +5,4 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /tmp/
8
+ .gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## [2.0.0](https://github.com/researchsquare/jekyll-translations/compare/v1.0.0...v2.0.0) (2023-09-25)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * Force 2.0.0 version
9
+
10
+ ### Features
11
+
12
+ * Add optional wrapping of translation with html tag ([4ed6c89](https://github.com/researchsquare/jekyll-translations/commit/4ed6c899207701d6d0bf3b76a361eaaec53deb11))
13
+ * Force 2.0.0 version ([2f37b24](https://github.com/researchsquare/jekyll-translations/commit/2f37b24974f5e34bee4c5357654992d27d80f540))
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Jekyll::Translations
2
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
3
+ This is a Jekyll plugin to manage translations from a variety of sources, including AWS S3 and PO Editor.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,14 +20,4 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
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.
23
+ If added correctly to the Gemfile, this plugin should work as a seamless replacement to local versions of the plugin that we have been using on our frontend Jekyll sites.
@@ -1,8 +1,12 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'jekyll/version'
4
+
1
5
  Gem::Specification.new do |spec|
2
6
  spec.name = "jekyll-translations"
3
- spec.version = "0.1.0"
4
- spec.authors = ["Jordan Dalton"]
5
- spec.email = ["jordan.dalton@researchsquare.com"]
7
+ spec.version = Jekyll::Translations::VERSION
8
+ spec.authors = ["Research Square Company Engineering"]
9
+ spec.email = ["customer@researchsquare.com"]
6
10
  spec.require_paths = ["lib"]
7
11
  spec.summary = %q{Translation tool for Jekyll}
8
12
  spec.homepage = "https://github.com/researchsquare/jekyll-translations"
@@ -5,9 +5,10 @@ module Jekyll
5
5
  module Translations
6
6
  class Generator < Jekyll::Generator
7
7
  def generate(site)
8
- translation_source = site.config['translations']['source']
8
+ translation_sources = site.config['translations']['sources']
9
9
 
10
- site.data['translations'] = JSON.parse(open(translation_source).read)
10
+ site.data['translations'] = {}
11
+ translation_sources.each { |key, value| site.data['translations'][key] = JSON.parse(open(value).read) }
11
12
  end
12
13
  end
13
14
 
@@ -15,17 +16,19 @@ module Jekyll
15
16
  @translations = []
16
17
  @localizationContext = nil
17
18
  @skipTranslationCheck = nil
19
+ @showTerm = false
18
20
  @debug_translations = false
19
21
 
20
- def translations
22
+ def translations(locale)
21
23
  return @translations if @translations
22
24
 
23
25
  site = @context.registers[:site]
24
26
  config = site.config['translations']
25
27
  @skipTranslationCheck = config['skipTranslationCheck']
28
+ @showTerm = !!config['showTerms']
26
29
  @debug_translations = !@skipTranslationCheck and ENV['DEBUG_TRANSLATIONS'].to_i === 1
27
30
 
28
- translation_data = site.data['translations']
31
+ translation_data = site.data['translations'][locale]
29
32
  translations = translation_data['common']
30
33
 
31
34
  if config['context'] and translation_data[config['context']]
@@ -42,11 +45,36 @@ module Jekyll
42
45
  return translated_hash
43
46
  end
44
47
 
48
+ def show_translation_term(translation, tag)
49
+ if @showTerm && !@showTermOverride
50
+ return "<#{tag} title=\"#{@lastTerm}\">#{translation}</#{tag}>"
51
+ end
52
+
53
+ return translation
54
+ end
55
+
56
+ def tns(text, args = [])
57
+ @showTermOverride = true;
58
+
59
+ translated = self.t(text, args)
60
+
61
+ @showTermOverride = false;
62
+
63
+ return translated
64
+ end
65
+
66
+ def ts(translation)
67
+ return self.show_translation_term(translation, 'div')
68
+ end
69
+
45
70
  def t(text, args = [])
46
71
  # If we've an array, translate each item and return
47
72
  return self.translate_array(text) if text.kind_of?(Array)
48
73
 
49
- @translations = self.translations
74
+ page = @context.environments.first['page']
75
+ locale = page['locale'] ? page['locale'] : 'default'
76
+
77
+ @translations = self.translations(locale)
50
78
 
51
79
  # Uncomment the following block to see a list of items missing translations
52
80
  # if @translations[text].nil?
@@ -71,8 +99,15 @@ module Jekyll
71
99
  args = args.to_s
72
100
  end
73
101
 
74
- return (@translations[text] % args) if not args.empty?
75
- return @translations[text]
102
+ if not args.empty?
103
+ translated = (@translations[text] % args)
104
+ else
105
+ translated = @translations[text]
106
+ end
107
+
108
+ @lastTerm = text
109
+
110
+ return self.show_translation_term(translated, 'span')
76
111
  end
77
112
  end
78
113
  end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Translations
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
@@ -1 +1,2 @@
1
1
  require 'jekyll/translations'
2
+ require 'jekyll/version'
metadata CHANGED
@@ -1,23 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Jordan Dalton
7
+ - Research Square Company Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-10 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
15
- - jordan.dalton@researchsquare.com
15
+ - customer@researchsquare.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/workflows/release.yml"
20
21
  - ".gitignore"
22
+ - CHANGELOG.md
21
23
  - Gemfile
22
24
  - README.md
23
25
  - bin/console
@@ -25,6 +27,7 @@ files:
25
27
  - jekyll-translations.gemspec
26
28
  - lib/jekyll-translations.rb
27
29
  - lib/jekyll/translations.rb
30
+ - lib/jekyll/version.rb
28
31
  homepage: https://github.com/researchsquare/jekyll-translations
29
32
  licenses:
30
33
  - MIT
@@ -44,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
47
  - !ruby/object:Gem::Version
45
48
  version: '0'
46
49
  requirements: []
47
- rubyforge_project:
48
- rubygems_version: 2.6.14
50
+ rubygems_version: 3.2.3
49
51
  signing_key:
50
52
  specification_version: 4
51
53
  summary: Translation tool for Jekyll