This gem adds the ability to swap words in strings marked for translation. It is an extension to fast_gettext.
For example, given you have set the system to replace <my project>
with GettextSwap
:
swapped = _('Welcome to <my project')
# => 'Welcome to GettextSwap'
Add this line to your application's Gemfile:
gem 'gettext_swap'
And then execute:
$ bundle
First you have to build a yaml file that will contain the rules for the swapper.
- The yaml should contain a main root element
swap
- Each rule consists of two sub elements:
search
- regular expression to search in the source, andreplace
- the string to use for replacement.
Example:
swap:
- search: '\bForeman\b(?!-)'
replace: 'Satellite'
- search: '\bsmart proxy\b(?!-)'
replace: 'capsule'
- search: '\bproxy\b(?!-)'
replace: 'Capsule'
To apply the rules, point GettextSwap to the file containing the rules.
GettextSwap.configure 'config/test/test.yaml'
This gem uses rubocop to validate styling and minitest framework for testing.
Run rubocop
and rake test
to verify your code.
Bug reports and pull requests are welcome on GitHub at https://github.com/ShimShtein/gettext_swap.
See LICENSE file.