awesome_translations 0.0.50 → 0.0.51

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
  SHA1:
3
- metadata.gz: 71559d649c9838d361131954f3a516da017ca8c7
4
- data.tar.gz: 7a424544ad774be257b1e5bec601230c7b2a3a4c
3
+ metadata.gz: dc90567edcc82ca8c14b5a0e557d197be4e4ce80
4
+ data.tar.gz: e4bae086230a613b4429fd306523aeb49927efbf
5
5
  SHA512:
6
- metadata.gz: 1fccfc503d47e0e418f9a89eefc92612f691f41a3c729dffccc477cb74770d0d65c4ecec85a8ba6e0907a827b6e915f67796daaf22053ad109a6ba2dcb79a053
7
- data.tar.gz: 5889856a581266af3fc7ff6388cb0396e2420a26d52dd2d948653194dc080e99642ae59675897f053980c5839584d97088b67e1bfd66c5170fc42e228b8b7e06
6
+ metadata.gz: 29cc8148769a499a617561caccac6d5ca06fccc9c72d1f66a82b95d60f358f7cda556140d458472b7fe52a73b3ca85eb7377eb2abaa6d0e5d1af6cded28ee1ed
7
+ data.tar.gz: ba8a1ed70f0d910ac7f56f7d5674665f4baeb40e113e1aefc19e93e31bbe8705c0cb530ab71e6b819ed970b75b0d5aec7b58751e5558bb4e0f08857270421169
@@ -24,6 +24,6 @@ class AwesomeTranslations::DuplicatesController < AwesomeTranslations::Applicati
24
24
  translation_value.destroy!
25
25
  end
26
26
 
27
- redirect_to :back
27
+ redirect_back(fallback_location: :root)
28
28
  end
29
29
  end
@@ -26,7 +26,7 @@ class AwesomeTranslations::GroupsController < AwesomeTranslations::ApplicationCo
26
26
  generator = AwesomeTranslations::CacheDatabaseGenerator.current
27
27
  generator.update_translations_for_group(@handler, @group)
28
28
 
29
- redirect_to :back
29
+ redirect_back(fallback_location: :root)
30
30
  end
31
31
 
32
32
  private
@@ -9,7 +9,7 @@ class AwesomeTranslations::HandlersController < AwesomeTranslations::Application
9
9
  generator = AwesomeTranslations::CacheDatabaseGenerator.current
10
10
  generator.update_handlers
11
11
 
12
- redirect_to :back
12
+ redirect_back(fallback_location: :root)
13
13
  end
14
14
 
15
15
  def update_groups_cache
@@ -19,7 +19,7 @@ class AwesomeTranslations::HandlersController < AwesomeTranslations::Application
19
19
  generator.update_groups_for_handler(handler_model)
20
20
  end
21
21
 
22
- redirect_to :back
22
+ redirect_back(fallback_location: :root)
23
23
  end
24
24
 
25
25
  def show
@@ -16,6 +16,6 @@ class AwesomeTranslations::MovalsController < AwesomeTranslations::ApplicationCo
16
16
  translation_value.migrate_to_awesome_translations_namespace!
17
17
  end
18
18
 
19
- redirect_to :back
19
+ redirect_back(fallback_location: :root)
20
20
  end
21
21
  end
@@ -1,4 +1,5 @@
1
1
  <% content_for(:header_title) { "Clean Up" } %>
2
+
2
3
  <%= form_for :clean_ups, url: clean_ups_path do |f| %>
3
4
  <div class="panel panel-default">
4
5
  <div class="panel-heading">
@@ -14,7 +15,7 @@
14
15
  </thead>
15
16
  <tbody>
16
17
  <% translations_to_clean_up.each do |translation| %>
17
- <tr class="translation-value" data-id="<%= translation.id %>">}
18
+ <tr class="translation-value" data-id="<%= translation.id %>">
18
19
  <td>
19
20
  <%= check_box_tag("c[#{translation.id}]", 1, true) %>
20
21
  </td>
@@ -8,7 +8,6 @@
8
8
  <%= content_for?(:header_title) ? content_for(:header_title) : "AwesomeTranslations" %>
9
9
  </title>
10
10
  <%= csrf_meta_tags %>
11
- <%= favicon_link_tag %>
12
11
 
13
12
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
14
13
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
@@ -21,7 +20,7 @@
21
20
 
22
21
  <%= content_for(:header_script) %>
23
22
  </head>
24
- <body class="<%= ["controller-#{controller_name}", "action-#{action_name}"] %>">
23
+ <body class="controller-<%= controller_name %> action-<%= action_name %>">
25
24
  <div class="navbar navbar-default navbar-static-top">
26
25
  <div class="container">
27
26
  <button class="navbar-toggle" data-target=".navbar-responsive-collapse" data-toggle="collapse" type="button">
@@ -29,7 +28,9 @@
29
28
  <span class="icon-bar"></span>
30
29
  <span class="icon-bar"></span>
31
30
  </button>
31
+
32
32
  <%= link_to "Awesome Translations", "/awesome_translations", class: "navbar-brand" %>
33
+
33
34
  <div class="navbar-collapse collapse navbar-responsive-collapse">
34
35
  <ul class="nav navbar-nav">
35
36
  <li>
@@ -1,4 +1,5 @@
1
1
  class AwesomeTranslations::ErbInspector::FileInspector
2
+ JS_FILE_EXTS = [".coffee", ".coffee.erb", ".es6", ".es6.erb", ".js", ".js.erb"]
2
3
  METHOD_NAMES = %w(t controller_t helper_t).freeze
3
4
  VALID_BEGINNING = '(^|\s+|\(|\{|\[|<%=\s*)'.freeze
4
5
 
@@ -23,6 +24,8 @@ class AwesomeTranslations::ErbInspector::FileInspector
23
24
 
24
25
  if extname == ".liquid"
25
26
  parse_content_liquid(line_no, line, translations_found, yielder)
27
+ elsif JS_FILE_EXTS.include?(extname)
28
+ parse_content_js(line_no, line, translations_found, yielder)
26
29
  else
27
30
  parse_content(line_no, line, translations_found, yielder)
28
31
  end
@@ -63,6 +66,16 @@ private
63
66
  end
64
67
  end
65
68
 
69
+ def parse_content_js(line_no, line, translations_found, yielder)
70
+ line.scan(/\I18n\.t\('(.+?)'\)/) do |match|
71
+ add_translation(line_no, "I18n.t", match[0], translations_found, yielder)
72
+ end
73
+
74
+ line.scan(/\I18n\.t\("(.+?)"\)/) do |match|
75
+ add_translation(line_no, "I18n-js.t", match[0], translations_found, yielder)
76
+ end
77
+ end
78
+
66
79
  def parse_content(line_no, line, translations_found, yielder)
67
80
  METHOD_NAMES.each do |method_name|
68
81
  if (last_method_match = line.match(/def\s+(.+?)(\(|\n|\r\n)/))
@@ -41,7 +41,7 @@ class AwesomeTranslations::ErbInspector::TranslationInspector
41
41
  private
42
42
 
43
43
  def generate_full_key
44
- if (@method == "t" || @method == "helper_t" || @method == "controller_t") && @key.start_with?(".")
44
+ if (@method == "t" || @method == "helper_t" || @method == "controller_t" || @method == "I18n-js.t") && @key.start_with?(".")
45
45
  @full_key = File.dirname(@file_path).to_s
46
46
 
47
47
  if @full_key.starts_with?("app/mailers")
@@ -67,7 +67,7 @@ private
67
67
  @full_key << ".#{@last_method}" if (is_mailer || is_controller) && @last_method && @method != "controller_t"
68
68
  @full_key << "."
69
69
  @full_key << @key.gsub(/\A\./, "")
70
- elsif @method == "t" || @method == "helper_t" || @method == "controller_t"
70
+ elsif @method == "I18n-js.t" || @method == "t" || @method == "helper_t" || @method == "controller_t"
71
71
  @full_key = @key
72
72
  else
73
73
  raise "Unknown method-name: '#{@method}'."
@@ -4,7 +4,7 @@ class AwesomeTranslations::ErbInspector
4
4
 
5
5
  def initialize(args = {})
6
6
  @args = args
7
- @args[:exts] ||= [".erb", ".haml", ".liquid", ".markerb", ".rb", ".rake", ".slim", "."]
7
+ @args[:exts] ||= [".erb", ".haml", ".liquid", ".markerb", ".rb", ".rake", ".slim", "."] + AwesomeTranslations::ErbInspector::FileInspector::JS_FILE_EXTS
8
8
 
9
9
  if @args[:dirs]
10
10
  @dirs = @args[:dirs]
@@ -1,3 +1,3 @@
1
1
  module AwesomeTranslations
2
- VERSION = "0.0.50".freeze
2
+ VERSION = "0.0.51".freeze
3
3
  end
@@ -24,9 +24,9 @@ describe AwesomeTranslations::GroupsController do
24
24
  it "updates translations" do
25
25
  expect(I18n.load_path).to_not include model_locales_path
26
26
 
27
- put :update, handler_id: "model_handler", id: "User", t: {
27
+ put :update, params: {handler_id: "model_handler", id: "User", t: {
28
28
  "activerecord.attributes.user.password" => {"da" => "Adgangskode", "de" => "Kenwort", "en" => "Password"}
29
- }
29
+ }}
30
30
 
31
31
  danish_user_translations = YAML.load_file(user_yml_path)
32
32
  expect(danish_user_translations["da"]["activerecord"]["attributes"]["user"]["password"]).to eq "Adgangskode"
@@ -35,9 +35,9 @@ describe AwesomeTranslations::GroupsController do
35
35
  it "updates paths" do
36
36
  key_to_update = "activerecord.attributes.role.role"
37
37
 
38
- put :update, handler_id: "model_handler", id: "Role", t: {
38
+ put :update, params: {handler_id: "model_handler", id: "Role", t: {
39
39
  key_to_update => {"da" => "Rolle", "de" => "Die type", "en" => "Role"}
40
- }
40
+ }}
41
41
 
42
42
  da_translation_value = AwesomeTranslations::CacheDatabaseGenerator::TranslationValue
43
43
  .joins(:translation_key)
@@ -57,7 +57,7 @@ describe AwesomeTranslations::GroupsController do
57
57
  end
58
58
 
59
59
  it "handles array translations" do
60
- put :update, handler_id: "rails_handler", id: "date_time", t: {
60
+ put :update, params: {handler_id: "rails_handler", id: "date_time", t: {
61
61
  "date.day_names" => {
62
62
  "1" => {
63
63
  "da" => "Mandag"
@@ -66,7 +66,7 @@ describe AwesomeTranslations::GroupsController do
66
66
  "da" => "Torsdag"
67
67
  }
68
68
  }
69
- }
69
+ }}
70
70
 
71
71
  translations = YAML.load_file(date_time_path)
72
72
 
@@ -77,7 +77,7 @@ describe AwesomeTranslations::GroupsController do
77
77
 
78
78
  it "#update_translations_cache" do
79
79
  request.env["HTTP_REFERER"] = handler_group_path("rails_handler", "date_time")
80
- post :update_translations_cache, handler_id: "rails_handler", id: "date_time"
80
+ post :update_translations_cache, params: {handler_id: "rails_handler", id: "date_time"}
81
81
  expect(response).to redirect_to handler_group_path("rails_handler", "date_time")
82
82
  end
83
83
  end
@@ -19,13 +19,13 @@ describe AwesomeTranslations::HandlersController do
19
19
  describe "#show" do
20
20
  it "renders the page" do
21
21
  AwesomeTranslations::CacheDatabaseGenerator.current.cache_translations
22
- get :show, id: "model_handler"
22
+ get :show, params: {id: "model_handler"}
23
23
  expect(response).to be_success
24
24
  end
25
25
 
26
26
  it "filters with missing translations" do
27
27
  AwesomeTranslations::CacheDatabaseGenerator.current.cache_translations
28
- get :show, id: "model_handler", with_missing_translations: "only_with"
28
+ get :show, params: {id: "model_handler", with_missing_translations: "only_with"}
29
29
 
30
30
  all_groups = AwesomeTranslations::CacheDatabaseGenerator::Group.all
31
31
  groups = assigns(:groups)
@@ -45,7 +45,7 @@ describe AwesomeTranslations::HandlersController do
45
45
  it "#update_groups_cache" do
46
46
  AwesomeTranslations::CacheDatabaseGenerator.current.cache_translations
47
47
  request.env["HTTP_REFERER"] = handler_path("rails_handler")
48
- post :update_groups_cache, id: "rails_handler"
48
+ post :update_groups_cache, params: {id: "rails_handler"}
49
49
  expect(response).to redirect_to handler_path("rails_handler")
50
50
  end
51
51
  end
@@ -10,7 +10,7 @@ describe UsersController do
10
10
  end
11
11
 
12
12
  it "#update" do
13
- patch :update, id: user.id, user: {email: "newemail@example.com"}
13
+ patch :update, params: {id: user.id, user: {email: "newemail@example.com"}}
14
14
  expect(response).to redirect_to user_url(user)
15
15
 
16
16
  # Ensure correct key
@@ -0,0 +1,2 @@
1
+ console.log(I18n.t(".hello_world"))
2
+ console.log(I18n.t("javascripts.absolute.key"))
@@ -9,6 +9,7 @@ describe AwesomeTranslations::ErbInspector::FileInspector do
9
9
 
10
10
  let(:files) { erb_inspector.files.to_a }
11
11
  let(:file_paths) { files.map(&:file_path) }
12
+ let(:js_translations_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/assets/javascripts/translations.js" } }
12
13
  let(:user_index_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/views/users/index.html.haml" } }
13
14
  let(:user_edit_inspector) { files.find { |file_inspector| file_inspector.file_path == "app/views/users/edit.html.liquid" } }
14
15
  let(:user_index_translations) { user_index_inspector.translations.to_a }
@@ -19,6 +20,17 @@ describe AwesomeTranslations::ErbInspector::FileInspector do
19
20
  expect(user_index_translations.length).to eq 3
20
21
  end
21
22
 
23
+ it "finds javascript translations" do
24
+ translation_keys = js_translations_inspector.translations.map(&:key)
25
+ translation_full_keys = js_translations_inspector.translations.map(&:full_key)
26
+
27
+ expect(translation_keys).to include ".hello_world"
28
+ expect(translation_keys).to include "javascripts.absolute.key"
29
+
30
+ expect(translation_full_keys).to include "assets.javascripts.translations.hello_world"
31
+ expect(translation_full_keys).to include "javascripts.absolute.key"
32
+ end
33
+
22
34
  it "finds liquid translations" do
23
35
  translation_keys = user_edit_inspector.translations.map(&:key)
24
36
 
@@ -12,13 +12,17 @@ describe AwesomeTranslations::ErbInspector do
12
12
 
13
13
  describe "#files" do
14
14
  it "should find haml-files" do
15
- expect(files.length).to eq 30
15
+ expect(files.length).to eq 32
16
16
  end
17
17
 
18
18
  it "should find haml-files" do
19
19
  expect(file_paths).to include "app/views/users/index.html.haml"
20
20
  end
21
21
 
22
+ it "should find js-files" do
23
+ expect(file_paths).to include "app/assets/javascripts/translations.js"
24
+ end
25
+
22
26
  it "should find erb-files" do
23
27
  expect(file_paths).to include "app/views/users/show.html.erb"
24
28
  end
@@ -9,7 +9,7 @@ describe AwesomeTranslations::ModelInspector do
9
9
  end
10
10
 
11
11
  it "#engines" do
12
- expected = [AwesomeTranslations::Engine, MoneyRails::Engine]
12
+ expected = [ActionView::Railtie, AwesomeTranslations::Engine, MoneyRails::Engine]
13
13
  expect(AwesomeTranslations::ModelInspector.engines.map(&:class).sort { |class1, class2| class1.name <=> class2.name }).to eq expected
14
14
  end
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.50
4
+ version: 0.0.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-16 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: array_enumerator
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0
33
+ version: 5.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0
40
+ version: 5.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: string-cases
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -248,6 +248,7 @@ files:
248
248
  - spec/dummy/README.rdoc
249
249
  - spec/dummy/Rakefile
250
250
  - spec/dummy/app/assets/javascripts/application.js
251
+ - spec/dummy/app/assets/javascripts/translations.js
251
252
  - spec/dummy/app/assets/stylesheets/application.css
252
253
  - spec/dummy/app/controllers/application_controller.rb
253
254
  - spec/dummy/app/controllers/locales_controller.rb
@@ -959,7 +960,6 @@ files:
959
960
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/zP/zPQqWF28I7kpoF1Dnj5EEarB0GpwOkUaA2Tz0hblh24.cache
960
961
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/ze/zedtAd8zH8Ioxo82-6BNpt6Ts6mMzO3imVF8J-NtYb0.cache
961
962
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/zh/zhMAhCSzLNtc-6pw-wSoR2Rz5C7dIaAfCZ_inNCngKg.cache
962
- - spec/dummy/tmp/pids/server.pid
963
963
  - spec/factories/group.rb
964
964
  - spec/factories/handler.rb
965
965
  - spec/factories/handler_translation.rb
@@ -1013,6 +1013,7 @@ test_files:
1013
1013
  - spec/controllers/handlers_controller_spec.rb
1014
1014
  - spec/controllers/users_controller_spec.rb
1015
1015
  - spec/dummy/app/assets/javascripts/application.js
1016
+ - spec/dummy/app/assets/javascripts/translations.js
1016
1017
  - spec/dummy/app/assets/stylesheets/application.css
1017
1018
  - spec/dummy/app/controllers/application_controller.rb
1018
1019
  - spec/dummy/app/controllers/locales_controller.rb
@@ -1726,7 +1727,6 @@ test_files:
1726
1727
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/ZS/zsbNbYYv-fy4XAGW2nAPt4I4bY2YUDa23WGZt_jKnVQ.cache
1727
1728
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/ZS/ZSjVZobcSitaP1Y4cHUI_-kywC2Q3JnYnpx2RdN3VwA.cache
1728
1729
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/Zw/ZwBNplTazyFPeZh5cxN-pYMEbPlumj2eWpK7v3ENe0o.cache
1729
- - spec/dummy/tmp/pids/server.pid
1730
1730
  - spec/factories/group.rb
1731
1731
  - spec/factories/handler.rb
1732
1732
  - spec/factories/handler_translation.rb
@@ -1 +0,0 @@
1
- 79400