Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Export locale overrides for default client/server files #18489

Closed
wants to merge 1 commit into from

Conversation

qmenchaca
Copy link

This commit creates a rake task to export a yml file of overridden client/server translations. In order to do this, I've created a second accessible function in the LocaleFileChecker, load_default_locale_files, that will return the contents of the server and client locale files located at config/locales/*.XX.yml, where the locale XX is the default for the Discourse configuration.

We then loop through all values configured in that TranslationOverride table and use the defaults above to determine if the overridden value is from the client.yml file or the server.yml file. Values for the specified type are then output by the rake task created here.

To call the rake task, use

rake locale_overrides: export[client]
rake locale_overrides: export[server]

This commit creates a rake task to export a yml file of overridden
client/server translations. In order to do this, I've created a second
accessible function in the LocaleFileChecker, load_default_locale_files,
that will return the contents of the server and client locale files
located at config/locales/*.XX.yml, where the locale XX is the default
for the Discourse configuration.

We then loop through all values configured in that TranslationOverride
table and use the defaults above to determine if the overridden value is
from the client.yml file or the server.yml file. Values for the
specified type are then output by the rake task created here.

To call the rake task, use

  rake locale_overrides: export[client]
  rake locale_overrides: export[server]
@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/export-customized-text-from-database-into-yml/53760/6

@qmenchaca
Copy link
Author

This is pretty limited in scope for now - it only considers values set in the default config/locales/{client,server}.XX.yml files, and does not tackle importing. But at least it gets the ball rolling towards tackling those.

Thanks for reviewing!

@pmusaraj
Copy link
Contributor

pmusaraj commented Oct 6, 2022

@qmenchaca this is kind of amazing... I needed just this feature earlier today and added it in via this commit: 4d80110

Can you try the two rake tasks described in that commit and see if they fit your needs? It uses JSON instead of YAML, but has both export and import capabilities.

@qmenchaca
Copy link
Author

@pmusaraj Wow, now this is serendipitous! I was definitely going for the "proper" yaml format to conform to the existing server/client file formats, but there is of course no need for that if the core contributors to the project don't agree.

That commit is both more compact than the work here, does more, and looks more than sufficient for my purposes, let alone other users.

@qmenchaca
Copy link
Author

@pmusaraj And I forgot to ask - now that this is merged in, is there a rough timeframe to get it tagged and released for use?

@pmusaraj
Copy link
Contributor

pmusaraj commented Oct 6, 2022

If your Discourse instance does not have any special configurations, you should be able to use it right away. You just need to rebuild, and that change will be picked up. (By default, self-hosters install Discourse from the tests-passed branch and that commit is already there.

Re: YAML vs JSON, I don't have a preference, but for export/importing the file format is not really important, it's a temporary file anyway.

Thanks for your work here, @qmenchaca, I'm a tiny bit sad that we're not merging this in, appreciate the effort nonetheless.

@pmusaraj pmusaraj closed this Oct 6, 2022
@qmenchaca
Copy link
Author

@pmusaraj This is great, I didn't spend more than a day of dev work doing this! :) All sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants