para-i18n 0.1.2 → 0.1.3

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: e4782fe23a947f29315a50521a2b37459805191e
4
- data.tar.gz: 569735c680d189e33941c807b978f6aa99c34f89
3
+ metadata.gz: 34b2ce3cde1648cdf50f7a0edf4f16914a3b31d5
4
+ data.tar.gz: a68844dba0800c59d7009dce60f9567690e9e244
5
5
  SHA512:
6
- metadata.gz: 98a6a60bff18fbb0f0dc9db479d22cd3ba03f36650f88dfc729e9f9b909092869542707682417c343551a26c764bca883ad915dbb91c26ad84dd2b8abbb62f1b
7
- data.tar.gz: b855da1d71f6b4435db90b925638aea1a05617cf036828dd51cb223f623a9e6c3e476a7f9f75f22869404d618a8b952a69265b1c2be8791f4c0a35c2f1c5e07d
6
+ metadata.gz: 67188e5b8e71be0ded33f270b2f88cc3fd11674e0394c854c6208da0166b48381a71ace6459895f087697cd7417843c930da1e5e1c07b3ea53bb1f787f44d875
7
+ data.tar.gz: dad4bd7ded6ee9443a7387116295115053861c8d977cce255237701f3fd54416a472bf8bc0ff17755d131c5ffd462a085f3f5facdd1b02f64e0c906ce8b043d9
@@ -1,3 +1,10 @@
1
+ class TranslationLocaleSelect
2
+ @onChange = ($field) ->
3
+ targetURL = $field.data('locale-select-target-url')
4
+ targetLocale = $field.val()
5
+ targetURL = targetURL.replace('target_locale=_', ['target_locale', targetLocale].join('='))
6
+ Turbolinks.visit(targetURL.replace(':locale', targetLocale))
7
+
1
8
  $(document).on 'page:change turbolinks:load', ->
2
9
  $('body').on 'change', '[data-locale-select]', (e) ->
3
- $(e.currentTarget).closest('form').submit()
10
+ TranslationLocaleSelect.onChange($(e.currentTarget))
@@ -1,4 +1,6 @@
1
1
  = para_form_for(resource, url: @component.relation_path(resource, :translation)) do |form|
2
+ = target_locale_select
3
+
2
4
  = form.fieldset do
3
5
  - translated_model_fields_for(resource.class).each do |field|
4
6
  = form.input field.field_name, as: :i18n, locale: @target_locale
@@ -0,0 +1,5 @@
1
+ .block.form-inputs
2
+ .form-group
3
+ = label :target_locale, t('i18n_admin.translations.choose_locale'), class: 'control-label col-md-3 pull-left'
4
+ .col-md-9
5
+ = select_tag :target_locale, options_for_select(locales.map { |locale| [locale, locale] }, target_locale), data: { :'locale-select' => true, selectize: true, multi: false, value: { text: target_locale, value: target_locale }, :'locale-select-target-url' => @component.relation_path(resource, :translation, action: :edit, target_locale: '_') }
@@ -1,11 +1,4 @@
1
1
  = page_top_bar(title: resource_title_for(resource), type: 'crud/translate')
2
2
 
3
3
  .page-content-wrap
4
- = form_tag @component.relation_path(resource, :translation, action: :edit), method: :get, class: 'form-horizontal form-group-separated' do
5
- .block.form-inputs
6
- .form-group
7
- = label :target_locale, t('i18n_admin.translations.choose_locale'), class: 'control-label col-md-3 pull-left'
8
- .col-md-9
9
- = select_tag :target_locale, options_for_select(@locales.map { |locale| [locale, locale] }, @target_locale), data: { :'locale-select' => true, selectize: true, multi: false, value: { text: @target_locale, value: @target_locale } }
10
-
11
4
  = render find_partial_for(resource, :translations_form)
@@ -1,4 +1,6 @@
1
1
  = para_form_for(resource, url: @component.relation_path(resource, :translation)) do |form|
2
+ = target_locale_select
3
+
2
4
  = form.fieldset do
3
5
  <%- translated_attributes.each do |field| -%>
4
6
  = form.input :<%= field.field_name %>, as: :i18n, locale: @target_locale
@@ -19,7 +19,8 @@ module Para
19
19
 
20
20
  initializer 'para.i18n.include_view_helpers' do
21
21
  ActiveSupport.on_load(:action_view) do
22
- include Para::I18n::TranslationsHelper
22
+ include Para::I18n::Helpers::TranslationsHelper
23
+ include Para::I18n::Helpers::TranslationsFormHelper
23
24
  end
24
25
  end
25
26
 
@@ -0,0 +1,12 @@
1
+ module Para
2
+ module I18n
3
+ module Helpers
4
+ module TranslationsFormHelper
5
+ def target_locale_select
6
+ render partial: 'para/admin/translations/target_locale_select',
7
+ locals: { locales: @locales, target_locale: @target_locale }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Para
2
+ module I18n
3
+ module Helpers
4
+ module TranslationsHelper
5
+ # TODO : Support images & co
6
+ def translated_model_fields_for(model)
7
+ model_field_mappings(model).fields.select do |field|
8
+ model.translated_attribute_names &&
9
+ model.translated_attribute_names.include?(field.name.to_sym)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Para
2
+ module I18n
3
+ module Helpers
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :TranslationsHelper
7
+ autoload :TranslationsFormHelper
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Para
2
2
  module I18n
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
data/lib/para/i18n.rb CHANGED
@@ -6,7 +6,6 @@ require 'para/i18n/fallbacks'
6
6
 
7
7
  require 'para/i18n/model'
8
8
  require 'para/i18n/resources_table'
9
- require 'para/i18n/translations_helper'
10
9
 
11
10
  require 'para/i18n/friendly_id'
12
11
 
@@ -16,6 +15,10 @@ require 'para/i18n/engine'
16
15
 
17
16
  module Para
18
17
  module I18n
18
+ extend ActiveSupport::Autoload
19
+
20
+ autoload :Helpers
21
+
19
22
  # Your code goes here...
20
23
  def self.method_missing(method, *args, &block)
21
24
  ::I18n.send(method, *args, &block)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - app/assets/javascripts/para/i18n.coffee
71
71
  - app/controllers/para/admin/translations_controller.rb
72
72
  - app/views/para/admin/resources/_translations_form.html.haml
73
+ - app/views/para/admin/translations/_target_locale_select.html.haml
73
74
  - app/views/para/admin/translations/edit.html.haml
74
75
  - bin/console
75
76
  - bin/setup
@@ -82,10 +83,12 @@ files:
82
83
  - lib/para/i18n/engine.rb
83
84
  - lib/para/i18n/fallbacks.rb
84
85
  - lib/para/i18n/friendly_id.rb
86
+ - lib/para/i18n/helpers.rb
87
+ - lib/para/i18n/helpers/translations_form_helper.rb
88
+ - lib/para/i18n/helpers/translations_helper.rb
85
89
  - lib/para/i18n/i18n_input.rb
86
90
  - lib/para/i18n/model.rb
87
91
  - lib/para/i18n/resources_table.rb
88
- - lib/para/i18n/translations_helper.rb
89
92
  - lib/para/i18n/version.rb
90
93
  - para-i18n.gemspec
91
94
  homepage: https://github.com/para-cms/para-i18n
@@ -108,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
111
  version: '0'
109
112
  requirements: []
110
113
  rubyforge_project:
111
- rubygems_version: 2.5.1
114
+ rubygems_version: 2.6.7
112
115
  signing_key:
113
116
  specification_version: 4
114
117
  summary: Para CMS I18n admin module for models
@@ -1,13 +0,0 @@
1
- module Para
2
- module I18n
3
- module TranslationsHelper
4
- # TODO : Support images & co
5
- def translated_model_fields_for(model)
6
- model_field_mappings(model).fields.select do |field|
7
- model.translated_attribute_names &&
8
- model.translated_attribute_names.include?(field.name.to_sym)
9
- end
10
- end
11
- end
12
- end
13
- end