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

Locale scaffolding #4246

Merged
merged 3 commits into from
Oct 3, 2024
Merged

Locale scaffolding #4246

merged 3 commits into from
Oct 3, 2024

Conversation

KludgeKML
Copy link
Contributor

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

Tidy up the locale files, add empty files for the additional 64 locales (frontend at the moment only supports en/cy) and add a task that will allow us to copy across all translations of a specific localisation tree.

Why

https://trello.com/c/woZwSv9D/363-create-translation-scaffolding-for-frontend

How

Use rails_translation_manager / i18n-tasks where possible (but they don't support this exact use case, so some workarounds)

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4246 October 2, 2024 10:27 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4246 October 2, 2024 10:30 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4246 October 2, 2024 12:57 Inactive
Copy link
Contributor

@leenagupte leenagupte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this out locally, and it works like a charm.

I've added recommendations for updating the task description inline.

There aren't any tests for this which isn't ideal, but as it's only to help local development and the changes can be easily unchanged, I think in this case it's ok.

@@ -0,0 +1,3 @@
---
no:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this one need to be in quotes? i.e. 'no':?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting. Added.

config/locales/cy.yml Show resolved Hide resolved
config/locales/en.yml Show resolved Hide resolved
# consolidation and are going to be removed.
# :nocov:
namespace :consolidation do
desc "Copy a locale key for all locales from government-frontend to frontend"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would good to add the example usage to the description with an explanation of the example. i.e. "Add a . to get a nested child" key etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you're using zsh like I am, you'll need to escape the brackets for the task to work, e.g

rake consolidation:copy_translation\[travel_advice\]

Otherwise you get an error:

zsh: no matches found: consolidation:copy_translation[travel_advice]

Perhaps this too could be added to the task description. Perhaps as a usage statement?

Apparently rake -D show the whole description if it's over multiple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm using zsh and I didn't need to escape the brackets. I know you need to put the whole thing in speechmarks if you're running it directly in kubernetes, but that's more about the colon I think. Let me try again locally and see what's what.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to add a bigger description, and have put the rake command in speechmarks, which is a standard way to get them to work in kubernetes and also works for zsh.

lib/tasks/consolidation.rake Show resolved Hide resolved
lib/tasks/consolidation.rake Show resolved Hide resolved
Created by making a new folder off locales (to avoid overwriting en.yml and cy.yml), then running this script (assumes you've checked out government-frontend in a directory parallel to this one).

for filename in ../../../government-frontend/config/locales/*.yml; do
  echo -e "---\n$(basename "$filename" .yml):\n" > "new/$(basename "$filename")"
done

- Note that in config/locales/en.yml we've enclosed "no" in quotes. This
is because in YAML no is a [reserved word](https://yaml.org/type/bool.html).
We use rails_translation_manager to regenerate our locale files.
When rails_translation_manager loads the YAML and interprets
"no" as a bool instead of a locale, it breaks.
Example use: rake "consolidation:copy_translation[components.figure]"

... will copy everything from the government-frontend translation files under the components.figure key into all relevant translation files. Note that government-frontend must be in a sibling directory to frontend.
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4246 October 3, 2024 12:26 Inactive
Copy link
Contributor

@leenagupte leenagupte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the Usage description ⭐

@KludgeKML KludgeKML merged commit 7d02592 into main Oct 3, 2024
12 checks passed
@KludgeKML KludgeKML deleted the locale-scaffolding branch October 3, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants