alchemy_cms icon indicating copy to clipboard operation
alchemy_cms copied to clipboard

select2 prompt text always in russian, regardless of the current locale

Open omnikron opened this issue 11 years ago • 4 comments

Just started using Alchemy for a new project - thanks for your work on this guys, it is great so far. This is a clean install of Alchemy based off the 3.0-stable branch, with the following gem versions: Rails: 4.1.8 Alchemy: 3.0.2 select2 - 3.5.9.1 Gemfile below

Issue

When editing tags (eg. for an image), if I click in the tag field and type nothing, the "Please enter at least one character" prompt always appears in Russian - to be specific, it tells me 'Пожалуйста, введите еще хотя бы 1 символ'. This is independent of what locale I have set.

(Probable) Cause

I did a bit of digging and determined that this is seems to because each select2 locale sets itself as the global default on page load. This means that because we require multiple locales at run time they are each setting themself as the default, overriding the previous one. Whatever gets required last will 'win', meaning that all select2 prompts will just be in that language. Hence Russian, because it's the last to get loaded.

The implementation of the 'auto set locale on include' functionality in select2 has changed between versions 3.4 and 3.5:

I can't see where in the Alchemy code the select2 locale is set. If I'm not just missing something obvious, I would suggest to fix this by requiring gem 'select2', ~> 3.5 and setting the locale like this.

I'd be happy to submit a PR, but I want to make sure I'm not just missing something or doing something stupid, as I'm new to Alchemy. Sorry for the wall of text!

Gemfile

source 'https://rubygems.org'

# core
gem 'rails', '4.1.8'
gem 'pg'
gem 'unicorn'

# assets
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'jbuilder', '~> 2.0'

# alchemy
gem "alchemy_cms", github: "magiclabs/alchemy_cms", branch: "3.0-stable"
gem "alchemy-devise", github: "magiclabs/alchemy-devise", branch: "2.0-stable"

# deployment
gem "capistrano", "~> 2.15.5", group: "development"

# development tools
gem 'pry', group: [:development, :test]
gem 'spring',      group: :development

# misc
gem 'sdoc', '~> 0.4.0', group: :doc

omnikron avatar Dec 08 '14 17:12 omnikron

Should be fixed in master and 3.0-stable with 6827f77cfb668d3c93769b36b92cca829aa12b8b and 7e322117c2ed42a29bfe83a47f14a38f7e3e1213

Thanks for reporting and investigating.

\o/ Welcome to Alchemy \o/

tvdeyen avatar Dec 08 '14 18:12 tvdeyen

Holy shit! That was fast! Can confirm it is working on 3.0-stable. AWESOME! :grin:

omnikron avatar Dec 08 '14 18:12 omnikron

@tvdeyen before I get too excited and forget - I think you might need to change select2-rails ~> 3.4 to select select2-rails ~> 3.5.2 in the gemspec as well - otherwise I believe this won't work for people who have version 3.4 installed. The $.fn.select2.locales array was only added in version 3.5.2, as far as I can tell.

Thanks again for the incredible turnaround!

omnikron avatar Dec 08 '14 19:12 omnikron

As far as I can tell, we need 3.5.9.1, because that includes select2 3.5.1:

https://github.com/argerim/select2-rails/commit/078ac54d4dfac4876e6944fd3e337d2a95dbb219

just updated the gemspec with 221985b423c4292be08e17b38155d83656c9831d and 03ebf3ab2331795442c250c302073c7da00df9b0

tvdeyen avatar Dec 08 '14 19:12 tvdeyen