rails_i18n_manager 1.0.0 → 1.0.1

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: 2cb2ef95ffdfb5f8460ccf2ff0b855e308a31d4375c8b90d977c48160323880c
4
- data.tar.gz: 78060ff50be1952e29a7113766b4aaccf48b1bf9b9394236b1259c8dd1e43e98
3
+ metadata.gz: dd793986118b3f29a0c7c135dd7ec8441203113c4c1873cad805ad2eb4b245a3
4
+ data.tar.gz: 909c10ed34654f3f6f759f2b36a9272689a50806d449bc50afa3a28934293f05
5
5
  SHA512:
6
- metadata.gz: '09dbe770f9e2d99e94c522e313ea3483b2546c0ee9edaa06e907335ade487abe300c931b1415c29f4395917a726c76bdea58089d8e6e296dd154847211b597ce'
7
- data.tar.gz: 32d1836c17e69a9a9b9f7cae727415def212fde9d01d6c63dc1cfa9a94551a88654a1629ae15f536067ee0fcbab37c38b5f053863aee7bf72edcc5a5aed81646
6
+ metadata.gz: 4f557ff74d5d911fc1fdbb1be32c70e685fd89716f6a4026d86f32c1d8d12378357ccc39124131dd273baf31e13c2bd926a19923a6dffbf37e2fde48776d9c03
7
+ data.tar.gz: d4ca43cc205e56ce7602d4d65ae33080f53631901ac7d96df12cdce2578ce7b6d3c9eb600b392b84df4de8d4a24f4f7dda22af4569d1ebebb16dab37671e9037
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rails I18n Manager
2
2
  > A complete translation editor and workflow
3
3
 
4
+ <a href="https://badge.fury.io/rb/rails_i18n_manager" target="_blank"><img height="21" style='border:0px;height:21px;' border='0' src="https://badge.fury.io/rb/rails_i18n_manager.svg" alt="Gem Version"></a>
4
5
  <a href='https://github.com/westonganger/rails_i18n_manager/actions' target='_blank'><img src="https://github.com/westonganger/rails_i18n_manager/workflows/Tests/badge.svg" style="max-width:100%;" height='21' style='border:0px;height:21px;' border='0' alt="CI Status"></a>
5
6
 
6
7
  Web interface to manage i18n translations helping to facilitate the editors of your translations. Provides a low-tech and complete workflow for importing, translating, and exporting your I18n translation files. Designed to allow you to keep the translation files inside your projects git repository where they should be.
@@ -27,7 +28,7 @@ First add the gem to your Gemfile
27
28
 
28
29
  ```ruby
29
30
  ### Gemfile
30
- gem "rails_i18n_manager", git: "https://github.com/westonganger/rails_i18n_manager"
31
+ gem "rails_i18n_manager"
31
32
  ```
32
33
 
33
34
  Then install and run the database migrations
@@ -153,11 +154,10 @@ Run server using: `bin/dev` or `cd test/dummy/; rails s`
153
154
  bundle exec rspec
154
155
  ```
155
156
 
156
- We can locally test different versions of Rails using `ENV['RAILS_VERSION']` and different database gems using `ENV['DB_GEM']`
157
+ We can locally test different versions of Rails using `ENV['RAILS_VERSION']`
157
158
 
158
159
  ```
159
160
  export RAILS_VERSION=7.0
160
- export DB_GEM=sqlite3
161
161
  bundle install
162
162
  bundle exec rspec
163
163
  ```
data/Rakefile CHANGED
@@ -11,8 +11,9 @@ load 'rails/tasks/statistics.rake'
11
11
 
12
12
  require 'bundler/gem_tasks'
13
13
 
14
- task :test do
15
- system("rspec", out: STDOUT)
16
- end
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task test: [:spec]
17
18
 
18
- task default: :test
19
+ task default: [:spec]
@@ -142,7 +142,7 @@ module RailsI18nManager
142
142
  locales = (app_locales || key_record.translation_app.additional_locales_array)
143
143
 
144
144
  ### Filter to just google translate supported languages
145
- locales = locales.intersection(GoogleTranslate.supported_locales)
145
+ locales = (locales & GoogleTranslate::SUPPORTED_LOCALES) # intersection
146
146
 
147
147
  default_translation_text = key_record.default_translation
148
148
 
@@ -4,69 +4,31 @@ module RailsI18nManager
4
4
  def self.translate(text, from:, to:)
5
5
  api_key = RailsI18nManager.config.google_translate_api_key
6
6
 
7
- if !supported_locales.include?(to.to_s) || Rails.env.test? || (api_key.blank? && Rails.env.development?)
7
+ if !SUPPORTED_LOCALES.include?(to.to_s) || Rails.env.test? || (api_key.blank? && Rails.env.development?)
8
8
  return false
9
9
  end
10
10
 
11
11
  if text.include?("<") && text.include?(">")
12
12
  ### Dont translate any HTML strings
13
- return nil
13
+ return false
14
14
  end
15
15
 
16
- EasyTranslate.translate(text, from: from, to: to, key: api_key)
17
-
18
- if translation
19
- str = translation.to_s
20
-
21
- if str.present?
22
- ### Replace single quote html entity with single quote character
23
- str = str.gsub("&#39;", "'")
16
+ translated_text = EasyTranslate.translate(text, from: from, to: to, key: api_key)
24
17
 
25
- if to.to_s == "es"
26
- str = str.gsub("% {", " %{").strip
27
- end
18
+ if translated_text.present?
19
+ ### Replace single quote html entity with single quote character
20
+ translated_text = translated_text.gsub("&#39;", "'")
28
21
 
29
- return str
22
+ if to.to_s == "es"
23
+ translated_text = translated_text.gsub("% {", " %{").strip
30
24
  end
25
+
26
+ return translated_text
31
27
  end
32
28
  end
33
29
 
34
30
  ### List retrieved from Google Translate (2022)
35
- @@supported_locales = ["af", "am", "ar", "az", "be", "bg", "bn", "bs", "ca", "ceb", "co", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fa", "fi", "fr", "fy", "ga", "gd", "gl", "gu", "ha", "haw", "he", "hi", "hmn", "hr", "ht", "hu", "hy", "id", "ig", "is", "it", "iw", "ja", "jw", "ka", "kk", "km", "kn", "ko", "ku", "ky", "la", "lb", "lo", "lt", "lv", "mg", "mi", "mk", "ml", "mn", "mr", "ms", "mt", "my", "ne", "nl", "no", "ny", "or", "pa", "pl", "ps", "pt", "ro", "ru", "rw", "sd", "si", "sk", "sl", "sm", "sn", "so", "sq", "sr", "st", "su", "sv", "sw", "ta", "te", "tg", "th", "tk", "tl", "tr", "tt", "ug", "uk", "ur", "uz", "vi", "xh", "yi", "yo", "zh", "zh-CN", "zh-TW", "zu"].freeze
36
- mattr_reader :supported_locales
37
-
38
- ### FOR official client
39
- # require "google/cloud/translate/v2" ### Offical Google Translate with API Key
40
- # def self.client
41
- # @@client ||= begin
42
- # api_key = RailsI18nManager.config.google_translate_api_key
43
- # if Rails.env.test? || (api_key.blank? && Rails.env.development?)
44
- # ### Skip Client
45
- # nil
46
- # else
47
- # Google::Cloud::Translate::V2.new(key: api_key)
48
- # end
49
- # end
50
- # end
51
- # def self.supported_locales
52
- # @@suported_locales ||= begin
53
- # if client
54
- # @@supported_locales = client.languages.map{|x| x.code}
55
- # else
56
- # []
57
- # end
58
- # end
59
- # end
60
- # def self.translate(text, from:, to:)
61
- # if client
62
- # begin
63
- # translation = client.translate(text, from: from, to: to)
64
- # rescue Google::Cloud::InvalidArgumentError
65
- # ### Error usually caused by an unsupported locale
66
- # return nil
67
- # end
68
- # end
69
- # end
31
+ SUPPORTED_LOCALES = ["af", "am", "ar", "az", "be", "bg", "bn", "bs", "ca", "ceb", "co", "cs", "cy", "da", "de", "el", "en", "eo", "es", "et", "eu", "fa", "fi", "fr", "fy", "ga", "gd", "gl", "gu", "ha", "haw", "he", "hi", "hmn", "hr", "ht", "hu", "hy", "id", "ig", "is", "it", "iw", "ja", "jw", "ka", "kk", "km", "kn", "ko", "ku", "ky", "la", "lb", "lo", "lt", "lv", "mg", "mi", "mk", "ml", "mn", "mr", "ms", "mt", "my", "ne", "nl", "no", "ny", "or", "pa", "pl", "ps", "pt", "ro", "ru", "rw", "sd", "si", "sk", "sl", "sm", "sn", "so", "sq", "sr", "st", "su", "sv", "sw", "ta", "te", "tg", "th", "tk", "tl", "tr", "tt", "ug", "uk", "ur", "uz", "vi", "xh", "yi", "yo", "zh", "zh-CN", "zh-TW", "zu"].freeze
70
32
 
71
33
  end
72
34
  end
@@ -79,14 +79,12 @@ module RailsI18nManager
79
79
 
80
80
  base_export_path = Rails.root.join("tmp/export/translations/")
81
81
 
82
- files_to_delete = Dir.glob("#{base_export_path}/*").each do |f|
83
- if File.ctime(f) > 1.minutes.ago
84
- `rm -rf #{f}`
85
- #File.delete(f)
86
- end
82
+ files_to_delete = Dir.glob("#{base_export_path}/*").select{|f| File.ctime(f) < 1.minutes.ago }
83
+ if !files_to_delete.empty?
84
+ FileUtils.rm_r(files_to_delete, force: true)
87
85
  end
88
86
 
89
- base_folder_path = File.join(base_export_path, "#{Time.now.to_i}/")
87
+ base_folder_path = File.join(base_export_path, "#{Time.now.to_i}-#{SecureRandom.hex(6)}/")
90
88
 
91
89
  FileUtils.mkdir_p(base_folder_path)
92
90
 
@@ -0,0 +1,3 @@
1
+ <li class="page-item">
2
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li class='page-item disabled'>
2
+ <%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li class="page-item">
2
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li class="page-item">
2
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
3
+ </li>
@@ -0,0 +1,9 @@
1
+ <% if page.current? %>
2
+ <li class="page-item active">
3
+ <%= content_tag :a, page, data: { remote: remote }, rel: page.rel, class: 'page-link' %>
4
+ </li>
5
+ <% else %>
6
+ <li class="page-item">
7
+ <%= link_to page, url, remote: remote, rel: page.rel, class: 'page-link' %>
8
+ </li>
9
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <%= paginator.render do %>
2
+ <nav>
3
+ <ul class="pagination">
4
+ <%= first_page_tag unless current_page.first? %>
5
+ <%= prev_page_tag unless current_page.first? %>
6
+ <% each_page do |page| %>
7
+ <% if page.left_outer? || page.right_outer? || page.inside_window? %>
8
+ <%= page_tag page %>
9
+ <% elsif !page.was_truncated? -%>
10
+ <%= gap_tag %>
11
+ <% end %>
12
+ <% end %>
13
+ <%= next_page_tag unless current_page.last? %>
14
+ <%= last_page_tag unless current_page.last? %>
15
+ </ul>
16
+ </nav>
17
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <li class="page-item">
2
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %>
3
+ </li>
@@ -25,3 +25,5 @@ table.table.table-striped.table-hover.space-above3.list-table
25
25
  td = x.additional_locales_array.join(", ")
26
26
  td
27
27
  = link_to "Edit", {action: :edit, id: x.id}
28
+
29
+ = paginate @translation_apps, views_prefix: "rails_i18n_manager"
@@ -48,3 +48,5 @@ table.table.table-striped.table-hover.space-above3.list-table
48
48
 
49
49
  - if x.any_missing_translations?
50
50
  span.space-left2 = link_to "Translate with Google", translate_missing_translations_path(id: x.id), method: :post, "data-confirm" => "Are you sure you want to proceed with translating the missing translations for this entry?"
51
+
52
+ = paginate @translation_keys, views_prefix: "rails_i18n_manager"
@@ -4,6 +4,7 @@ require 'kaminari'
4
4
  require "zip"
5
5
  require "activerecord-import"
6
6
  require "csv"
7
+ require "easy_translate"
7
8
 
8
9
  module RailsI18nManager
9
10
  class Engine < ::Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module RailsI18nManager
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_i18n_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-03 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -238,6 +238,13 @@ files:
238
238
  - app/views/layouts/rails_i18n_manager/application.js.erb
239
239
  - app/views/rails_i18n_manager/form_builder/_basic_field.html.erb
240
240
  - app/views/rails_i18n_manager/form_builder/_error_notification.html.erb
241
+ - app/views/rails_i18n_manager/kaminari/_first_page.html.erb
242
+ - app/views/rails_i18n_manager/kaminari/_gap.html.erb
243
+ - app/views/rails_i18n_manager/kaminari/_last_page.html.erb
244
+ - app/views/rails_i18n_manager/kaminari/_next_page.html.erb
245
+ - app/views/rails_i18n_manager/kaminari/_page.html.erb
246
+ - app/views/rails_i18n_manager/kaminari/_paginator.html.erb
247
+ - app/views/rails_i18n_manager/kaminari/_prev_page.html.erb
241
248
  - app/views/rails_i18n_manager/shared/_flash.html.slim
242
249
  - app/views/rails_i18n_manager/translation_apps/_breadcrumbs.html.slim
243
250
  - app/views/rails_i18n_manager/translation_apps/_filter_bar.html.slim