From 693c3cf154959be9dcda168715be8f96c3c585da Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Tue, 11 Jun 2024 18:07:19 -0400 Subject: [PATCH 1/3] Tools: Add i18n string workflow --- .github/workflows/i18n.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/i18n.yml diff --git a/.github/workflows/i18n.yml b/.github/workflows/i18n.yml new file mode 100644 index 00000000..008232ef --- /dev/null +++ b/.github/workflows/i18n.yml @@ -0,0 +1,35 @@ +name: Translate Strings + +on: + workflow_dispatch: + push: + branches: + - update/generate-i18n-strings + schedule: + - cron: '0 6,18 * * *' + +jobs: + translation-strings: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + + - name: i18n + uses: WordPress/wporg-repo-tools/.github/actions/i18n@trunk + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --no_taxonomies --post_types=page --url=https://wordpress.org/wp-json/wp/v2/ --textdomain=wporg + + - name: Remove the translation context + run: | + sed -i "s/, 'page title'//" extra/translation-strings.php + sed -i "s/_x(/__(/" extra/translation-strings.php + + - name: Commit and push + # Using a specific hash here instead of a tagged version, for risk mitigation, since this action modifies our repo. + uses: actions-js/push@a52398fac807b0c1e5f1492c969b477c8560a0ba # 1.3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: update/generate-i18n-strings + message: 'Update translation strings' From cf88ba46ec27de1387b4c46d411e63739b5b4771 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Tue, 11 Jun 2024 18:55:44 -0400 Subject: [PATCH 2/3] Filter page titles to enable translations Fixes #436 --- .../themes/wporg-main-2022/functions.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/source/wp-content/themes/wporg-main-2022/functions.php b/source/wp-content/themes/wporg-main-2022/functions.php index bbe10ff5..4f5eb5bd 100644 --- a/source/wp-content/themes/wporg-main-2022/functions.php +++ b/source/wp-content/themes/wporg-main-2022/functions.php @@ -25,6 +25,8 @@ add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\use_parent_page_title', 10, 3 ); add_filter( 'render_block_data', __NAMESPACE__ . '\update_header_template_part_class' ); add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); +add_filter( 'the_title', __NAMESPACE__ . '\translate_the_title', 1, 2 ); +add_filter( 'single_post_title', __NAMESPACE__ . '\translate_the_title', 1, 2 ); /** * Enqueue scripts and styles. @@ -274,7 +276,7 @@ function use_parent_page_title( $block_content, $block, $instance ) { // Loop up to the first child page, this is the section title. while ( $parent ) { $url = get_permalink( $parent->ID ); - $title = $parent->post_title; + $title = get_the_title( $parent ); $parent = get_post_parent( $parent ); } @@ -319,6 +321,27 @@ function update_header_template_part_class( $block ) { return $block; } +/** + * Replace the title with the translated page title. + * + * @param string $title The current title, ignored. + * @param int $post_id The post_id of the page. + * + * @return string + */ +function translate_the_title( $title, $post_id = null ) { + if ( is_admin() ) { + return $title; + } + + $post = get_post( $post_id ); + if ( $post && 'page' === $post->post_type ) { + $title = translate( $post->post_title, 'wporg' ); // phpcs:ignore + } + + return $title; +} + /** * Prevent easy access to the Site Editor. * From ec68780aaa49abd90b41a07295e4a53f5a8c4b55 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 11 Jun 2024 23:01:53 +0000 Subject: [PATCH 3/3] Update translation strings --- extra/translation-strings.php | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 extra/translation-strings.php diff --git a/extra/translation-strings.php b/extra/translation-strings.php new file mode 100644 index 00000000..4694986b --- /dev/null +++ b/extra/translation-strings.php @@ -0,0 +1,52 @@ +