https://github.com/holyshared/yaml-translator
Translate for the locales configuration file
https://github.com/holyshared/yaml-translator
diff gem i18n locale ruby translation
Last synced: 11 months ago
JSON representation
Translate for the locales configuration file
- Host: GitHub
- URL: https://github.com/holyshared/yaml-translator
- Owner: holyshared
- License: mit
- Created: 2017-02-04T06:51:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-09T02:27:06.000Z (over 8 years ago)
- Last Synced: 2025-04-21T17:58:38.312Z (about 1 year ago)
- Topics: diff, gem, i18n, locale, ruby, translation
- Language: Ruby
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 0
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yaml-translator
yaml-translator is a gem that translates yaml format translation files into each language.
The translation method supports google translate api in built-in.
[](https://badge.fury.io/rb/yaml-translator)
[](https://travis-ci.org/holyshared/yaml-translator)
[](https://coveralls.io/github/holyshared/yaml-translator?branch=master)
[](https://codeclimate.com/github/holyshared/yaml-translator)
## Basic usage
The method of translating the language file is as follows.
```ruby
dir = File.dirname(__FILE__)
translator = ::YamlTranslator.create(
:google_translate,
api_key: ENV['GOOGLE_TRANSLATE_API_KEY']
)
english_locale = translator.file("#{dir}/en.yml")
japanese_locale = english_locale.to(:ja)
p japanese_locale.to_s # convert to japanese locale yaml format
p japanese_locale.save_to(dir) # Write a ja.yml
german_locale = english_locale.to(:de)
p german_locale.to_s # convert to german locale yaml format
p german_locale.save_to(dir) # Write a de.yml
```
## Translation of difference
The method of translating the difference is as follows.
```ruby
dir = File.dirname(__FILE__)
translator = ::YamlTranslator.create(
:google_translate,
api_key: ENV['GOOGLE_TRANSLATE_API_KEY']
)
diff_locale = translator.file("/path/to/before/en.yml").diff("/path/to/after/en.yml")
diff_locale.to(:ja).save
```
translate into multiple languages
```ruby
diff_locale = translator.file("/path/to/before/en.yml").diff("/path/to/after/en.yml")
diff_locale.all(%w(ja en)).each { |r| r.save }
```
## Run the test
bundle install
rake spec