On my spree 1.2.x, i have spree_multi_lingual and spree_editor.
In the admin, when i switch locale with the spree_multi_lingual dropdown, the tinyMCE doesn't reload with the translated content because translated_fields are created only if we change the locale.
I worked on a solution who need to be improved.
At this time, i'm able to use those extensions if i override the spree_multi_lingual_class.js.coffee. It works only for 2 languages on the website, it use a setTimeout (i hate that) and he doesn't check if spree_editor is running or not.
This is my concept proof :
$(document).ready ->
ml = new SpreeMultiLingual
ml.create_localized_fields()
$("#spree_multi_lingual_dropdown").change (e) ->
ml.change_language(@.value)
# declare the class in global scope so we can extend it from within our app
class window.SpreeMultiLingual
constructor: ->
@translated_fields = window.spree_multi_lingual.translated_fields
@default_locale = window.spree_multi_lingual.backend_locale
@current_locale = @default_locale
@other_locale = $('#spree_multi_lingual_dropdown option').not(':selected').attr('value')
create_localized_fields: =>
for field in @translated_fields
field_name = @localized_field_name(field)
if !$("#" + field_name).length
@duplicate_field(field)
setTimeout =>
@show_fields()
, 1000
change_language: (locale) =>
@current_locale = locale
@make_sure_field_exists_for_language()
@show_fields()
duplicate_field: (field) =>
field_name = @localized_field_name(field)
if $("#" + field)[0]
new_field_name_value = $("#" + field).attr("name").substring(0,$("#" + field).attr("name").length - 1) + "_" + @other_locale + "]"
new_field = $("#" + field).clone().attr("id", field_name).attr("name", new_field_name_value).removeClass("sml-localized-field-"+@default_locale)
value = eval("window.spree_multi_lingual.translated_fields_values['#{field_name}']")
new_field.val(value) if value
$("#" + field).after(new_field)
@add_localized_class(field_name)
@add_localized_class(field, @default_locale)
make_sure_field_exists_for_language: =>
for field in @translated_fields
field_name = @localized_field_name(field)
if !$("#" + field_name).length
@duplicate_field(field)
show_fields: =>
for field in $(".sml-localized-field")
$(field).hide()
$(field).next('.mceEditor').hide()
if $(field).hasClass("sml-localized-field-#{@current_locale}")
if $(field).is('textarea')
$(field).next('.mceEditor').show()
else
$(field).show()
localized_field_name: (field) =>
(field + "_" + @other_locale)
add_localized_class: (id, locale = @other_locale) =>
@add_class(id, "sml-localized-field")
@add_class(id, "sml-localized-field-" + locale)
add_class: (id, klass) ->
$("#" + id).addClass(klass) unless $("#" + id).hasClass(klass)
On my spree 1.2.x, i have spree_multi_lingual and spree_editor.
In the admin, when i switch locale with the spree_multi_lingual dropdown, the tinyMCE doesn't reload with the translated content because translated_fields are created only if we change the locale.
I worked on a solution who need to be improved.
At this time, i'm able to use those extensions if i override the spree_multi_lingual_class.js.coffee. It works only for 2 languages on the website, it use a setTimeout (i hate that) and he doesn't check if spree_editor is running or not.
This is my concept proof :
Could you help me to improve this class ?