# Déplacer la langue personnalisée vers la langue par défaut (ES\_XX en es)

**URL:** <https://meta.discourse.org/t/move-custom-language-to-default-one-es-xx-to-es/265598>\
**Category:** Self-hosting\
**Created:** [Mai 19, 2023, 8:47 UTC](https://meta.discourse.org/t/move-custom-language-to-default-one-es-xx-to-es/265598 "2023-05-19T20:47:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [Mai 22, 2023, 3:01 UTC](https://meta.discourse.org/t/move-custom-language-to-default-one-es-xx-to-es/265598/2 "2023-05-22T15:01:32Z")

</div>

L’exécution de ce qui suit dans une console Rails devrait fonctionner&nbsp;:

```ruby
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 "Migration de #{table} vers la locale new_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) }

```

---

_[View the full topic](https://meta.discourse.org/t/move-custom-language-to-default-one-es-xx-to-es/265598)._
