Skip to content

Commit 1409640

Browse files
committed
removed other locales
1 parent 85d4a48 commit 1409640

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ end
2525

2626
form do |f|
2727
# ...
28-
f.translated_inputs "Translated fields" do |t|
28+
f.translated_inputs "Translated fields", switch_locale: false do |t|
2929
t.input :title
3030
t.input :content
3131
end
3232
# ...
3333
end
3434
```
35+
If `switch_locale` is set, each tab will be rendered switching locale.
3536

3637
## Friendly ID
3738

config/locales/en.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/active_admin/globalize3/engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ActiveAdmin
22
module Globalize3
33
class Engine < ::Rails::Engine
4-
initializer "Railsyard precompile hook" do |app|
4+
initializer "Railsyard precompile hook", group: :assets do |app|
55
app.config.assets.precompile += [
66
"active_admin/active_admin_globalize3.css",
77
"active_admin/active_admin_globalize3.js"

lib/active_admin/globalize3/form_builder_extension.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ module Globalize3
33
module FormBuilderExtension
44
extend ActiveSupport::Concern
55

6-
def translated_inputs(name = "Translations", &block)
6+
def translated_inputs(name = "Translations", options = {}, &block)
7+
options.symbolize_keys!
8+
switch_locale = options.fetch(:switch_locale, false)
79
form_buffers.last << template.content_tag(:div, class: "activeadmin-translations") do
810
template.content_tag(:ul, class: "available-locales") do
911
I18n.available_locales.sort.map do |locale|
1012
template.content_tag(:li) do
11-
template.content_tag(:a, I18n.t(:"active_admin.globalize3.language.#{locale}"), href:".locale-#{locale}")
13+
I18n.with_locale(switch_locale ? locale : I18n.locale) do
14+
template.content_tag(:a, I18n.t(:"active_admin.globalize3.language.#{locale}"), href:".locale-#{locale}")
15+
end
1216
end
1317
end.join.html_safe
1418
end <<
@@ -18,7 +22,9 @@ def translated_inputs(name = "Translations", &block)
1822
fields = proc do |form|
1923
form.input(:locale, as: :hidden)
2024
form.input(:id, as: :hidden)
21-
block.call(form)
25+
I18n.with_locale(switch_locale ? locale : I18n.locale) do
26+
block.call(form)
27+
end
2228
end
2329
inputs_for_nested_attributes(
2430
for: [:translations, translation ],

0 commit comments

Comments
 (0)