Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 4e70073

Browse files
committed
Consistent (fixed) order for translations in show
1 parent 0230ee2 commit 4e70073

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/active_admin/globalize/attributes_table_extension.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def translatable?(field)
8383
# @param [Symbol] tag tag to enclose field translation
8484
# @param [Symbol] initial_locale locale to set as not hidden
8585
def field_translations(field, tag, initial_locale)
86-
@record.translations.map do |translation|
86+
available_translations.map do |translation|
8787
# Classes for translation span only first element is visible
8888
css_classes = ['field-translation', "locale-#{translation.locale}"]
8989
# Initially only element for selected locale is visible
@@ -98,7 +98,7 @@ def field_translations(field, tag, initial_locale)
9898

9999
def block_locale_selectors
100100
content_tag(:ul, class: 'available-locales locale-selector') do
101-
@record.translations.map(&:locale).map do |locale|
101+
available_translations.map(&:locale).map do |locale|
102102
default = 'default' if locale == I18n.default_locale
103103
content_tag(:li, class: 'translation-tab') do
104104
I18n.with_locale(locale) do
@@ -112,13 +112,17 @@ def block_locale_selectors
112112
# Return flag elements to show the given locale using javascript
113113
def inline_locale_selectors
114114
content_tag(:span, class: 'inline-locale-selector') do
115-
@record.translations.map do |translation|
115+
available_translations.map do |translation|
116116
# Build a link to show the given translation
117117
link_to(flag_icon(translation.locale), '#', class: 'ui-translation-trigger', data: {locale: translation.locale})
118118
end.join(' ').html_safe
119119
end
120120
end
121121

122+
def available_translations
123+
@record_translations ||= @record.translations.order(:locale)
124+
end
125+
122126
end
123127
end
124128
end

0 commit comments

Comments
 (0)