Export customized text from database into YML

Admin interface allows overwriting any stranslations which is very healful not just for utilizing community translation while updating them with custom phrases that suit a specific community, but at the same time it is also a very good way to gradually translate a new language, without the need of updating the code, hence rebuilding the cache. However, it would be great if the customized translations can be exported from the database and somehoe merged back into the corresponding YAML files to make it available in the main repository. Is there a way of doing that which I am not aware of?

3 Likes

I don’t think there is a job for this but 100% support these two tasks, which could help you out here

rake export:locale_overrides:server > server.xx.yml
rake export:locale_overrides:client > client.xx.yml
6 Likes

Does anyone know if anyone’s made this yet?

@sam I have run the task to export locals but it doesn’t work
I have the message below

Don't know how to build task 'export:locale_overrides:server' (See the list of available tasks with `rake --tasks`)

Any idea ?

Nobody made the task yet, going to add a #pr-welcome for clarity

2 Likes

This is something I’ve been thinking about as well, and have created a PR:

3 Likes

To close the loop here, @mqmenchaca and myself worked on this at the same time without knowledge of the other working on it. And came up with PRs just a few hours apart! I had already merged my PR to core just before seeing Max’s, so sadly we can’t merge his work in core. Very much appreciate the contribution nonetheless, @mqmenchaca!

The commit that adds this feature is this one: DEV: Add a rake task to export/import translation overrides (#18487) ¡ discourse/discourse@4d80110 ¡ GitHub

To export, run bin/rake export:translation_overrides (it will create a JSON file with the overrides).

To import in a separate instance, copy the exported JSON file there and run bin/rake import:file["filename"].

4 Likes

Hi there. Please, can you describe the steps to run it?

./launcher enter app
bin/rake export:translation_overrides

Returns:

rake aborted!
ActiveRecord::NoDatabaseError: We could not find your database: discourse. Which can be found in the database configuration file located at config/database.yml

That seems to be an issue with your environment. When I enter the container in my own self-hosted instance, I can run rake commands just fine.

1 Like

I’m using Discourse behind Nginx, that could be related? It’s possible to use the command using a database outside the container?

OK, I was doing some tests and I have the file exported.

If I modify that file changing es_XX to es (and not more else, taking care about the format and character encoding of the file) and importing the previous exported file, it should works?

I want to move previous overrides to default es language on our instance :slight_smile: