Skip to content

[Tooling] Add GlotPress integration for Fluent localization files #756

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

Closed
wants to merge 8 commits into from

Conversation

iangmaia
Copy link
Contributor

@iangmaia iangmaia commented Jun 4, 2025

Related:

What does it do?

This PR integrates the new Fluent-to-PO conversion actions from release-toolkit to enable a complete translation workflow between the project's Fluent localization files (.ftl) and GlotPress, allowing for:

  • Source generation: Converts the source English Fluent file to PO format (.pot) for uploading to GlotPress
  • Translation sync: Downloads translated PO files from GlotPress and converts them back to Fluent format, adding them to the project
  • Locale management: Supports MAG16 locales with mapping between GlotPress and project locale codes; this was implemented just to limit the languages we know we support, but this mapping can be easily updated in the future

Key new lanes

  • generate_source_po_file lane - Converts en-US/main.ftl to en-US.pot for GlotPress upload
  • download_translations lane - Downloads all available translations from GlotPress following the supported locales list and updates local Fluent files
  • generate_fluent_file_from_po lane - Converts individual PO files back to Fluent format
  • download_po_files_from_glotpress lane - Downloads PO files for all supported locales

Localization workflow

A day-to-day workflow, to be automated in the next PRs, could work like this (suggestions are welcome):

  1. New features are implemented, new localization strings need to be created (or updated)
  2. Developers add strings to the source language file wp_localization/localization/en-US/main.ftl.
  3. With a certain frequency or based on a trigger (e.g. merge to trunk? A daily scheduled build?), we run generate_source_po_file and commit the updated wp_localization/glotpress/en-US.pot.
  4. A wpcom job uploads the updated en-US source file to GlotPress (see 184627-ghe-Automattic/wpcom )
  5. Again with a given frequency, we fetch the translations, generate the Fluent files and commit them to the project (or create a PR for review) by running download_translations.

Comment on lines +6 to +7
gem 'fastlane-plugin-wpmreleasetoolkit', '~> 13.2', git: 'https://github.com/wordpress-mobile/release-toolkit.git',
branch: 'iangmaia/fluent-po-conversion-actions'

Choose a reason for hiding this comment

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

🎗️ Just adding a comment here to serve as a reminder to not merge this PR until we'll have a new version of the release-toolkit shipped and this Gemfile updated to point to it.

Comment on lines 255 to 256
# Ensure PO output directory exists
FileUtils.mkdir_p(download_dir)

Choose a reason for hiding this comment

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

I'd suggest to use Dir.mktmpdir do |download_dir| … end instead, not only because this is more idiomatic Ruby when we need a temp dir, but also to guarantee that the temp folder being cleared and deleted once the job is done, and thus that any subsequent runs won't accidentally use a previously downloaded file left over from a previous run.

Comment on lines 268 to 269
# Download PO file using curl
sh("curl -s -o '#{po_file_path}' '#{download_url}'")

Choose a reason for hiding this comment

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

This is far from idiomatic Ruby, requires shelling out, and is not secure (especially it's vulnerable to command injections).

There are better methods in Ruby to download files from an URI. For example, something like this should work I think:

require 'open-uri'
File.write(po_file_path, URI.open(download_url).read)

@iangmaia iangmaia marked this pull request as draft June 5, 2025 09:44
@iangmaia
Copy link
Contributor Author

iangmaia commented Jun 5, 2025

Moved PR back to Draft after a few discussions with @AliSoftware about the actions generating / parsing the intermediate files and possible alternatives.
This PR and the overall process is still valid and perhaps won't change much regardless of the parsing / generation approach.

@iangmaia iangmaia force-pushed the iangmaia/fluent-to-glotpress branch from 2381d75 to e55d460 Compare June 12, 2025 15:40
@iangmaia
Copy link
Contributor Author

This PR is superseded by #765

@iangmaia iangmaia closed this Jun 14, 2025
@iangmaia iangmaia deleted the iangmaia/fluent-to-glotpress branch June 14, 2025 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants