Skip to content

Commit 5c89be9

Browse files
committed
Merge branch 'main' into copilot/fix-1570774-111592377-8d1e68ec-3eae-4dfa-abd4-ecdb9fb7198f
2 parents afd1ffb + c602513 commit 5c89be9

File tree

10 files changed

+151
-10
lines changed

10 files changed

+151
-10
lines changed

.github/workflows/copilot-setup-steps.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ jobs:
1717

1818
steps:
1919
- name: Checkout code
20-
uses: actions/checkout@v6
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@v3
24+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
2525
with:
2626
files: "composer.json"
2727

2828
- name: Set up PHP environment
2929
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@v2
30+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
3131
with:
3232
php-version: 'latest'
3333
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Install Composer dependencies & cache dependencies
4040
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@v3
41+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3
4242
env:
4343
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4444
with:

.github/workflows/issue-triage.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
---
2-
name: Issue Triage
2+
name: Issue and PR Triage
33

44
'on':
55
issues:
66
types: [opened]
7+
pull_request_target:
8+
types: [opened]
79
workflow_dispatch:
810
inputs:
911
issue_number:
10-
description: 'Issue number to triage (leave empty to process all)'
12+
description: 'Issue/PR number to triage (leave empty to process all)'
1113
required: false
1214
type: string
1315

16+
permissions:
17+
issues: write
18+
pull-requests: write
19+
actions: write
20+
contents: read
21+
models: read
22+
1423
jobs:
1524
issue-triage:
1625
uses: wp-cli/.github/.github/workflows/reusable-issue-triage.yml@main
1726
with:
18-
issue_number: ${{ github.event_name == 'workflow_dispatch' && inputs.issue_number || github.event.issue.number }}
27+
issue_number: >-
28+
${{
29+
(github.event_name == 'workflow_dispatch' && inputs.issue_number) ||
30+
(github.event_name == 'pull_request_target' && github.event.pull_request.number) ||
31+
(github.event_name == 'issues' && github.event.issue.number) ||
32+
''
33+
}}

.github/workflows/regenerate-readme.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
- "features/**"
1111
- "README.md"
1212

13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
1317
jobs:
1418
regenerate-readme:
1519
uses: wp-cli/.github/.github/workflows/reusable-regenerate-readme.yml@main
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Welcome New Contributors
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
branches:
7+
- main
8+
- master
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
welcome:
15+
uses: wp-cli/.github/.github/workflows/reusable-welcome-new-contributors.yml@main

.typos.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[default]
2+
extend-ignore-re = [
3+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$",
4+
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on",
5+
"(#|//)\\s*spellchecker:ignore-next-line\\n.*"
6+
]
7+
8+
[files]
9+
extend-exclude = [
10+
"features/*.feature"
11+
]

assets/theme-i18n.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
{
4444
"name": "Aspect ratio name"
4545
}
46+
],
47+
"dimensionSizes": [
48+
{
49+
"name": "Dimension size name"
50+
}
4651
]
4752
},
4853
"shadow": {
@@ -95,6 +100,11 @@
95100
{
96101
"name": "Aspect ratio name"
97102
}
103+
],
104+
"dimensionSizes": [
105+
{
106+
"name": "Dimension size name"
107+
}
98108
]
99109
},
100110
"spacing": {

features/updatepo.feature

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ Feature: Update existing PO files from a POT file
488488
#: foo-plugin.php:1
489489
msgid "Some string"
490490
msgstr ""
491+
492+
#: foo-plugin.php:2
493+
msgid "Some other string"
494+
msgstr ""
491495
"""
492496
And a foo-plugin/foo-plugin-de_DE.po file:
493497
"""
@@ -528,6 +532,58 @@ Feature: Update existing PO files from a POT file
528532
"PO-Revision-Date: 2018-05-02T22:06:24+00:00\n"
529533
"""
530534

535+
Scenario: Keeps POT file order of translations
536+
Given an empty foo-plugin directory
537+
And a foo-plugin/foo-plugin.pot file:
538+
"""
539+
# Copyright (C) 2018 Foo Plugin
540+
# This file is distributed under the same license as the Foo Plugin package.
541+
msgid ""
542+
msgstr ""
543+
"Project-Id-Version: Foo Plugin\n"
544+
"Content-Type: text/plain; charset=UTF-8\n"
545+
"X-Domain: foo-plugin\n"
546+
547+
#: foo-plugin.php:1
548+
msgid "First string"
549+
msgstr ""
550+
551+
#: foo-plugin.php:10
552+
msgid "Second string"
553+
msgstr ""
554+
555+
#: foo-plugin.php:20
556+
msgid "Third string"
557+
msgstr ""
558+
"""
559+
And a foo-plugin/foo-plugin-de_DE.po file:
560+
"""
561+
# Copyright (C) 2018 Foo Plugin
562+
# This file is distributed under the same license as the Foo Plugin package.
563+
msgid ""
564+
msgstr ""
565+
"Project-Id-Version: Foo Plugin\n"
566+
"Content-Type: text/plain; charset=UTF-8\n"
567+
"Language: de_DE\n"
568+
"X-Domain: foo-plugin\n"
569+
570+
#: foo-plugin.php:20
571+
msgid "Third string"
572+
msgstr "Dritte Zeichenfolge"
573+
574+
#: foo-plugin.php:1
575+
msgid "First string"
576+
msgstr "Erste Zeichenfolge"
577+
"""
578+
579+
When I run `wp i18n update-po foo-plugin/foo-plugin.pot foo-plugin/foo-plugin-de_DE.po`
580+
Then STDOUT should be:
581+
"""
582+
Success: Updated 1 file.
583+
"""
584+
And STDERR should be empty
585+
And the contents of the foo-plugin/foo-plugin-de_DE.po file should match /First string.*Second string.*Third string/s
586+
531587
Scenario: Reports unchanged files when POT hasn't changed
532588
Given an empty foo-plugin directory
533589
And a foo-plugin/foo-plugin.pot file:

src/BladeGettextExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected static function compileBladeToPhp( $text ) {
4242
/**
4343
* {@inheritdoc}
4444
*
45-
* Note: In the parent PhpCode class fromString() uses fromStringMultiple() (overriden here)
45+
* Note: In the parent PhpCode class fromString() uses fromStringMultiple() (overridden here)
4646
*/
4747
public static function fromStringMultiple( $text, array $translations, array $options = [] ) {
4848
$php_string = static::compileBladeToPhp( $text );

src/JsFunctionsScanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private function resolveExpressionCallee( Node\CallExpression $node ) {
368368
}
369369

370370
/**
371-
* Returns wether or not a comment precedes a node.
371+
* Returns whether or not a comment precedes a node.
372372
* The comment must be before the node and on the same line or the one before.
373373
*
374374
* @param Node\Comment $comment The comment.

src/UpdatePoCommand.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public function __invoke( $args, $assoc_args ) {
101101
// Uses gmdate() for consistency across different server timezones.
102102
$po_translations->setHeader( 'PO-Revision-Date', gmdate( 'Y-m-d\TH:i:sP' ) );
103103

104-
if ( ! $po_translations->toPoFile( $file->getPathname() ) ) {
104+
// Reorder translations to match POT file order.
105+
$ordered_translations = $this->reorder_translations( $po_translations, $pot_translations );
106+
107+
if ( ! $ordered_translations->toPoFile( $file->getPathname() ) ) {
105108
WP_CLI::warning( sprintf( 'Could not update file %s', $file->getPathname() ) );
106109
continue;
107110
}
@@ -200,4 +203,31 @@ private function translations_differ( Translations $original, Translations $upda
200203

201204
return false;
202205
}
206+
207+
/**
208+
* Reorder translations to match the POT file order.
209+
*
210+
* @param Translations $po_translations The merged PO translations.
211+
* @param Translations $pot_translations The POT translations (source of truth for order).
212+
*
213+
* @return Translations Translations object with entries in POT file order.
214+
*/
215+
private function reorder_translations( Translations $po_translations, Translations $pot_translations ) {
216+
$ordered = new Translations();
217+
218+
// Copy headers from the merged PO translations.
219+
foreach ( $po_translations->getHeaders() as $name => $value ) {
220+
$ordered->setHeader( $name, $value );
221+
}
222+
223+
// Add translations in POT file order.
224+
foreach ( $pot_translations as $pot_entry ) {
225+
$po_entry = $po_translations->find( $pot_entry );
226+
if ( $po_entry ) {
227+
$ordered[] = $po_entry->getClone();
228+
}
229+
}
230+
231+
return $ordered;
232+
}
203233
}

0 commit comments

Comments
 (0)