tolgee_liquid 0.1.1 → 0.1.8

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
2
  SHA256:
3
- metadata.gz: 9cd9abf93aafe9fcbc1382685660eae4a7f6bb56fc7552559732f49833032892
4
- data.tar.gz: '08ea31a081f4aba7f8c55adf989ffbf4b3c591784eb76706984125de2e716c42'
3
+ metadata.gz: 135c8ea7a31e3de305940140011512b70acbcb3a2f1b1ce11ee576c8c5ae4837
4
+ data.tar.gz: 9cf05ee3c4c5e8616fc83788300c6d14f50ab8b22401dcd9f05ab87e2881d16a
5
5
  SHA512:
6
- metadata.gz: bf3feac6e7028c221788d4a25acae048db1bff38bda024516b98902deda0682b5879093f5a800673b6634c67944bdf6e594250d78379b209d9bcc6ceeb389dd4
7
- data.tar.gz: b4ec4b5de66a1e1927ed5e14c96e681894373fdbfb3151e8150b01ba7c6279c18df6a8714c868c73dd8c1626db38139672f084836331704081a03ae08dc98057
6
+ metadata.gz: ec5446a4b41750ef8b374ecb1bd8bbbb77d1afc2c29e134067e587b52206c48bf0e767b0f22fdbe1a70714322e4d23bbaca9f8575b5b5751a9370f61076300ab
7
+ data.tar.gz: 486b3b5a4fd57539dd567d88f1488786b3253977a98eba3767b40d59a460e01f89b0e8a9a10cb99203609331b12ff358d7bd52d35b1016c24a3abd9d88358afb
data/.travis.yml CHANGED
@@ -4,4 +4,25 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.6.10
7
- before_install: gem install bundler -v 1.17.2
7
+
8
+ before_install:
9
+ - gem install bundler -v 1.17.2
10
+
11
+ script:
12
+ - bin/setup
13
+ - bundle exec rake spec
14
+ - gem build tolgee_liquid.gemspec
15
+
16
+ before_deploy:
17
+ - export TRAVIS_TAG=$(git describe --tags --abbrev=0)
18
+
19
+ deploy:
20
+ provider: rubygems
21
+ api_key: "$RUBYGEMS_API_KEY"
22
+ on:
23
+ tags: true
24
+
25
+ branches:
26
+ only:
27
+ - main
28
+ - /^v\d+(\.\d+(\.\d+)?)?$/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tolgee_liquid (0.1.1)
4
+ tolgee_liquid (0.1.8)
5
5
  message_format (~> 0.0.8)
6
6
 
7
7
  GEM
@@ -12,7 +12,7 @@ GEM
12
12
  bigdecimal (3.1.8)
13
13
  camertron-eprun (1.1.1)
14
14
  cldr-plurals-runtime-rb (1.1.0)
15
- concurrent-ruby (1.3.1)
15
+ concurrent-ruby (1.3.2)
16
16
  crack (1.0.0)
17
17
  bigdecimal
18
18
  rexml
data/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # TolgeeLiquid
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/tolgee_liquid`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A Ruby gem that integrates the [Tolgee Platform](https://tolgee.io/integrations) with Shopify's [Liquid template language](https://github.com/Shopify/liquid).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ If you are developing a multilingual web application using the Liquid template language, check out the Tolgee Platform (translation as a service). It enhances your translation workflow, making it more efficient and accurate.
6
+
7
+ This gem focuses on the "In-Context" translation integration. See the example project at https://github.com/cccccroge/tolgee-rails-liquid.
6
8
 
7
9
  ## Installation
8
10
 
11
+ ### Prerequisite
12
+ Make sure you have liquid installed.
13
+
14
+ ### Install
15
+
9
16
  Add this line to your application's Gemfile:
10
17
 
11
18
  ```ruby
@@ -16,13 +23,87 @@ And then execute:
16
23
 
17
24
  $ bundle
18
25
 
19
- Or install it yourself as:
26
+ ## Usage
20
27
 
21
- $ gem install tolgee_liquid
28
+ ### Setup Credentials
29
+ Add the following block to your application initialization. If you are using Rails, place it in config/initializers/tolgee.rb:
22
30
 
23
- ## Usage
31
+ ```.rb
32
+ TolgeeLiquid.configure do |config|
33
+ config.api_url = 'https://example.tolgee.io'
34
+ config.api_key = <TOLGEE_API_KEY>
35
+ config.project_id = <TOLGEE_PROJECT_ID>
36
+ end
37
+ ```
38
+ This allows the gem to fetch data from the corresponding Tolgee project in development mode.
39
+
40
+ ### Register `t` method for Liquid
41
+ There are two ways to setup.
42
+
43
+ #### Use Decorator
44
+ If you already have your own translation method `t` defined.
45
+ ```.rb
46
+ module MyFilterContainsTranslationMethod
47
+ def t(name, vars = {})
48
+ # Own implementation
49
+ end
50
+ end
51
+
52
+ Liquid::Template.register_filter(MyFilterContainsTranslationMethod)
53
+ ```
54
+
55
+ Add the prefix `with_tolgee` on translation method:
56
+ ```.rb
57
+ module MyFilterContainsTranslationMethod
58
+ with_tolgee def t(name, vars = {})
59
+ # Own implementation
60
+ end
61
+ end
62
+ ```
63
+
64
+ Note that the arguments of the original t method must match the format above (the first argument being the translation key, and an optional hash argument providing variables for string interpolation). Otherwise, it won't work correctly.
65
+
66
+ #### Use gem's `t` method
67
+ You can use the t method provided by the gem, which utilizes ICU MessageFormat patterns under the hood.
68
+
69
+ ```.rb
70
+ Liquid::Template.register_filter(TolgeeFilter)
71
+ ```
72
+
73
+ ### Use `t` filter in Liquid template
24
74
 
25
- TODO: Write usage instructions here
75
+ Example Liquid snippet:
76
+ ```.html
77
+ <div>{{ 'key.nested_key' | t: fruit: 'Pitaya' }}</div>
78
+ ```
79
+
80
+ Example application's controller code for Rails project:
81
+ ```.rb
82
+ class PagesController < ApplicationController
83
+ def index
84
+ # get liquid template file...
85
+ template = Liquid::Template.parse(liquid)
86
+
87
+ # provide translations and meta data
88
+ tolgee_registers = TolgeeLiquid.registers({
89
+ locale: 'en',
90
+ mode: 'development',
91
+ static_data: {
92
+ en: YAML.load_file(Rails.root.join('config', 'locales', 'en.yml')),
93
+ },
94
+ })
95
+
96
+ html = template.render({}, registers: tolgee_registers)
97
+ # put html to view...
98
+ end
99
+ end
100
+ ```
101
+
102
+ Example translation yaml file:
103
+ ```.yml
104
+ key:
105
+ nested_key: "I like {fruit}!"
106
+ ```
26
107
 
27
108
  ## Development
28
109
 
@@ -32,7 +113,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
113
 
33
114
  ## Contributing
34
115
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tolgee_liquid.
116
+ Bug reports and pull requests are welcome.
36
117
 
37
118
  ## License
38
119
 
data/bin/deploy ADDED
@@ -0,0 +1,61 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ current_branch=$(git rev-parse --abbrev-ref HEAD)
6
+
7
+ # Make sure we are on "main"
8
+ if [ "$current_branch" != "main" ]; then
9
+ echo "Error: You must be on 'main' to deploy."
10
+ exit 1
11
+ fi
12
+
13
+ # Get commits to release
14
+ last_release_tag=$(git describe --tags --abbrev=0)
15
+ commits=$(git log --pretty=format:"%h %s" $last_release_tag..HEAD)
16
+
17
+ if [ -z "$commits" ]; then
18
+ echo "No new commits to release."
19
+ exit 0
20
+ fi
21
+
22
+ # Preview commits
23
+ echo "Commits to be released:"
24
+ while read -r commit_hash commit_message; do
25
+ pr_title=$(git log -1 --pretty="%b" $commit_hash | sed -n '/^Pull Request Title:/s/^Pull Request Title: //p')
26
+ echo "$commit_hash $commit_message"
27
+ if [ -n "$pr_title" ]; then
28
+ echo " Pull Request Title: $pr_title"
29
+ fi
30
+ done <<< "$commits"
31
+
32
+ # Bump version
33
+ read -p "Bump version (major/minor/patch)? " version_bump
34
+ current_version=$(ruby -r ./lib/tolgee_liquid/version.rb -e "puts TolgeeLiquid::VERSION")
35
+ case "$version_bump" in
36
+ major)
37
+ new_version=$(ruby -e "puts Gem::Version.new('$current_version').bump.bump.to_s")
38
+ ;;
39
+ minor)
40
+ new_version=$(ruby -e "puts Gem::Version.new('$current_version').bump.to_s")
41
+ ;;
42
+ patch)
43
+ new_version=$(ruby -e "version = Gem::Version.new('$current_version'); segments = version.segments; segments[-1] += 1; puts segments.join('.')")
44
+ ;;
45
+ *)
46
+ echo "Invalid version bump type."
47
+ exit 1
48
+ ;;
49
+ esac
50
+
51
+ echo "Bumping version from $current_version to $new_version"
52
+ sed -i "s/VERSION = \"$current_version\"/VERSION = \"$new_version\"/" lib/tolgee_liquid/version.rb
53
+
54
+ # Create commit and tag for new version
55
+ git add lib/tolgee_liquid/version.rb
56
+ bundle install
57
+ git add Gemfile.lock
58
+ git commit -m "Bump version to $new_version" --no-edit
59
+ git tag v$new_version
60
+ git push origin tag v$new_version
61
+ git push
@@ -1,3 +1,3 @@
1
1
  module TolgeeLiquid
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolgee_liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen He
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-01 00:00:00.000000000 Z
11
+ date: 2024-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: message_format
@@ -96,6 +96,7 @@ files:
96
96
  - README.md
97
97
  - Rakefile
98
98
  - bin/console
99
+ - bin/deploy
99
100
  - bin/setup
100
101
  - lib/tolgee_liquid.rb
101
102
  - lib/tolgee_liquid/translate.rb
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubygems_version: 3.0.3.1
125
+ rubygems_version: 3.1.6
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Tolgee Integration for Liquid