i18n-translate-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71f8f118546601bbfee4360253cf059d8cb3faa0de6210f05e1338e6738e4236
4
+ data.tar.gz: 316cc07955d6f578e1051555a384978cf3ee1edff565d3a91d7b3aef6ec949ea
5
+ SHA512:
6
+ metadata.gz: 6bb9b862232d458079e65834736709596af1f848f2d5d64af9d943b0477a98ed55084a31639747a85d713991b75d65e4bc6817080a3471a875ae253a837e7b56
7
+ data.tar.gz: 1913e3a6df5d076b2ed64cfe3433d5bacdae63a84637c22babba025a4df7cb9b7d05cbf3f3f7db7602b6c976ae7c74e8b394b764217191889cc2a1fd94767934
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in i18n-translate-rails.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Yusuke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # I18n::Translate::Rails
2
+
3
+ Translate rails locale files into other languages using the Google Translate api.
4
+
5
+ ## System Requirements
6
+
7
+ rails 7.0.4
8
+ [^We have not confirmed that it works, but it probably works with other versions.]
9
+
10
+ ## Setup
11
+
12
+ 1. Install a config file.
13
+ ```
14
+ $ bin/rails i18n:translate:install
15
+ ```
16
+
17
+ 2. Set google api key to `i18n_translate_api_key` in credentials.
18
+
19
+ ## Use
20
+ ```
21
+ $ bin/rails i18n:translate[config/locales/en.yml,ja]
22
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1 @@
1
+ engine: :google_translate
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/i18n/translate/rails/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "i18n-translate-rails"
7
+ spec.version = I18n::Translate::Rails::VERSION
8
+ spec.authors = ["Yusuke"]
9
+ spec.email = ["yusuke@slidict.io"]
10
+
11
+ spec.summary = "Automatic translation locale"
12
+ spec.description = "Automatic translation into the target language based on the base i18n yaml."
13
+ spec.homepage = "https://blog.slidict.io/gems/i18n-translate-rails"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/slidict/i18n-translate-rails/"
19
+ spec.metadata["changelog_uri"] = "https://github.com/slidict/i18n-translate-rails/releases"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "yaml-translator"
33
+
34
+ # For more information and examples about making a new gem, check out our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module I18n
4
+ module Translate
5
+ module Rails
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rails/version"
4
+
5
+ module I18n
6
+ module Translate
7
+ module Rails
8
+ class Error < StandardError; end
9
+ class Railtie < ::Rails::Railtie
10
+ config.i18n_translate_engine = nil
11
+ rake_tasks do
12
+ load "tasks/i18n/translate.rake"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "yaml-translator"
5
+ require_relative "i18n/translate/rails"
6
+
7
+ module I18n::Translate
8
+ def self.root
9
+ File.expand_path '../..', __FILE__
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :i18n do
4
+ desc 'Translate an i18n file.'
5
+ task :translate, [:path, :target_lang] => :environment do |task, args|
6
+ dirname = File.dirname(args.path)
7
+ filename = File.basename(args.path)
8
+ matches = filename.match(/^(.*?).en.yml$/)
9
+ prefix = matches ? "#{matches[1]}." : ""
10
+ engine = YAML.load(File.read(Rails.root.join("config", "i18n-translate.yml")))["engine"]
11
+
12
+ translator = ::YamlTranslator.create(
13
+ engine,
14
+ api_key: ::Rails.application.credentials.i18n_translate_api_key
15
+ )
16
+
17
+ english_locale = translator.file(args.path)
18
+ japanese_locale = english_locale.to(args.target_lang.to_sym)
19
+
20
+ japanese_locale.save_to(dirname, {prefix: prefix})
21
+ puts "Translated #{args.path} to #{args.target_lang}"
22
+ end
23
+
24
+ desc 'Install i18n-translate'
25
+ task :install do
26
+ target_filepath = "#{Rails.root}/config/i18n-translate.yml"
27
+ if File.exist?(target_filepath)
28
+ puts "Already exist file. #{target_filepath}"
29
+ else
30
+ FileUtils.cp("#{I18n::Translate.root}/config/i18n-translate.yml", target_filepath)
31
+ puts "Installed the config. #{target_filepath}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,8 @@
1
+ module I18n
2
+ module Translate
3
+ module Rails
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-translate-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml-translator
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Automatic translation into the target language based on the base i18n
28
+ yaml.
29
+ email:
30
+ - yusuke@slidict.io
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - config/i18n-translate.yml
42
+ - i18n-translate-rails.gemspec
43
+ - lib/i18n-translate-rails.rb
44
+ - lib/i18n/translate/rails.rb
45
+ - lib/i18n/translate/rails/version.rb
46
+ - lib/tasks/i18n/translate.rake
47
+ - sig/i18n/translate/rails.rbs
48
+ homepage: https://blog.slidict.io/gems/i18n-translate-rails
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://blog.slidict.io/gems/i18n-translate-rails
53
+ source_code_uri: https://github.com/slidict/i18n-translate-rails/
54
+ changelog_uri: https://github.com/slidict/i18n-translate-rails/releases
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.6.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.3.7
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Automatic translation locale
74
+ test_files: []