What’s the proper way to do it? From mysql, using queries within Discourse, maybe with some script?
It seems that using a plugin to create custom language causes some issues in our instance.
What’s the proper way to do it? From mysql, using queries within Discourse, maybe with some script?
It seems that using a plugin to create custom language causes some issues in our instance.
Executing the following in a rails console should work:
old_locale = "es_XX"
new_locale = "es"
DB.exec <<~SQL
UPDATE users
SET locale = '#{new_locale}'
WHERE locale = '#{old_locale}'
SQL
DB.exec <<~SQL
UPDATE site_settings
SET value = '#{new_locale}'
WHERE name = 'default_locale' AND value = '#{old_locale}'
SQL
DB.exec <<~SQL
UPDATE translation_overrides
SET locale = '#{new_locale}'
WHERE locale = '#{old_locale}'
SQL
DB.exec <<~SQL
UPDATE theme_translation_overrides
SET locale = '#{new_locale}'
WHERE locale = '#{old_locale}'
SQL
def fix_search_data(model)
key = "#{model}_id"
table = "#{model}_search_data"
puts "Migrating #{table} to new_locale locale."
sql = <<~SQL
UPDATE #{table}
SET locale = '#{new_locale}'
WHERE #{key} IN (
SELECT #{key}
FROM #{table}
WHERE locale = '#{old_locale}'
LIMIT 100000
)
SQL
loop do
count = DB.exec(sql)
break if count == 0
puts "Migrated #{count} rows of #{table} to new locale."
end
end
%w[category tag topic user].each { |model| fix_search_data(model) }
Thanks! What’s the most effective method to deal with overrided strings in locale?
Code seems to work but not with overrided in destination ‘default’ locale.
Running the following in the rails console should help:
I18n.reload!
ExtraLocalesController.clear_cache!
MessageBus.publish("/i18n-flush", refresh: true)
If it doesn’t, restarting the server should definitely work.
Thanks, it seems to be related to something in my instance but maybe I didn’t express myself well in my previous message
I copy the error message, just in case:
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_translation_overrides_on_locale_and_translation_key"
DETAIL: Key (locale, translation_key)=(es, js.docs.categories) already exists.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.