FIX: Allow theme translations to be accessed in initializers (#8285)
Previously theme translations were loaded along with other plugin API scripts. These run after pre-initializers and initializers when the app boots. This commit moves theme translation loading into pre-initializers, so their behaviour matches core translations more closely.
This commit is contained in:
parent
c008443f2d
commit
ee5799805c
|
@ -60,7 +60,7 @@ class ThemeField < ActiveRecord::Base
|
||||||
validates :name, format: { with: /\A[a-z_][a-z0-9_-]*\z/i },
|
validates :name, format: { with: /\A[a-z_][a-z0-9_-]*\z/i },
|
||||||
if: Proc.new { |field| ThemeField.theme_var_type_ids.include?(field.type_id) }
|
if: Proc.new { |field| ThemeField.theme_var_type_ids.include?(field.type_id) }
|
||||||
|
|
||||||
BASE_COMPILER_VERSION = 13
|
BASE_COMPILER_VERSION = 14
|
||||||
DEPENDENT_CONSTANTS = [BASE_COMPILER_VERSION,
|
DEPENDENT_CONSTANTS = [BASE_COMPILER_VERSION,
|
||||||
GlobalSetting.cdn_url]
|
GlobalSetting.cdn_url]
|
||||||
COMPILER_VERSION = Digest::SHA1.hexdigest(DEPENDENT_CONSTANTS.join)
|
COMPILER_VERSION = Digest::SHA1.hexdigest(DEPENDENT_CONSTANTS.join)
|
||||||
|
@ -181,6 +181,9 @@ class ThemeField < ActiveRecord::Base
|
||||||
data = translation_data
|
data = translation_data
|
||||||
|
|
||||||
js = <<~JS
|
js = <<~JS
|
||||||
|
export default {
|
||||||
|
name: "theme-#{theme_id}-translations",
|
||||||
|
initialize() {
|
||||||
/* Translation data for theme #{self.theme_id} (#{self.name})*/
|
/* Translation data for theme #{self.theme_id} (#{self.name})*/
|
||||||
const data = #{data.to_json};
|
const data = #{data.to_json};
|
||||||
|
|
||||||
|
@ -191,9 +194,11 @@ class ThemeField < ActiveRecord::Base
|
||||||
}
|
}
|
||||||
cursor[#{self.theme_id}] = data[lang];
|
cursor[#{self.theme_id}] = data[lang];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
JS
|
JS
|
||||||
|
|
||||||
js_compiler.append_plugin_script(js, 0)
|
js_compiler.append_module(js, "discourse/pre-initializers/theme-#{theme_id}-translations", include_variables: false)
|
||||||
rescue ThemeTranslationParser::InvalidYaml => e
|
rescue ThemeTranslationParser::InvalidYaml => e
|
||||||
errors << e.message
|
errors << e.message
|
||||||
end
|
end
|
||||||
|
|
|
@ -208,8 +208,8 @@ class ThemeJavascriptCompiler
|
||||||
@content << script + "\n"
|
@content << script + "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_module(script, name)
|
def append_module(script, name, include_variables: true)
|
||||||
script.prepend theme_variables
|
script = "#{theme_variables}#{script}" if include_variables
|
||||||
template = Tilt::ES6ModuleTranspilerTemplate.new {}
|
template = Tilt::ES6ModuleTranspilerTemplate.new {}
|
||||||
@content << template.module_transpile(script, "", name)
|
@content << template.module_transpile(script, "", name)
|
||||||
rescue MiniRacer::RuntimeError => ex
|
rescue MiniRacer::RuntimeError => ex
|
||||||
|
|
Loading…
Reference in New Issue