Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] [Translation] Update XLIFF source tags with new translation:update-xliff-sources command#53630

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
squrious wants to merge3 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromsqurious:translation/update-source-option-in-extract-command

Conversation

squrious
Copy link
Contributor

@squrioussqurious commentedJan 24, 2024
edited
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#33041
LicenseMIT

Context

Currently, XLIFF files generated with thetranslation:extract command use the translation key to create the<source> tag:

<trans-unitid="hVNhFLX"resname="navbar.home">  <source>navbar.home</source>  <target>__navbar.home</target></trans-unit>

But usually this<source> tag contains the default locale text to be translated (XLIFF 1.2,XLIFF 2.0).

Also, the<source> tag is already used inXliffFileLoader to populate the catalogue metadata (but only for v1).

Proposed solution

This PR adds three features:

  • use thesource metadata (if available) to create thesource tag inXliffFileDumper
  • use thesource tag to populate thesource metadata inXliffFileLoader for XLIFF 2.0
  • add atranslation:update-xliff-sources command to update thesource tag in XLIFF files

Result

Given the following entries in XLIFF files:

<!-- translations/messages.en.xlf--><trans-unitid="hVNhFLX"resname="navbar.home">  <source>navbar.home</source>  <target>Home</target></trans-unit>
<!-- translations/messages.fr.xlf--><trans-unitid="hVNhFLX"resname="navbar.home">  <source>navbar.home</source>  <target>__navbar.home</target></trans-unit>

Running

bin/console translation:update-xliff-sources

Will produce updates the files with:

<!-- translations/messages.en.xlf--><trans-unitid="hVNhFLX"resname="navbar.home">  <source>Home</source>  <target>Home</target></trans-unit>
<!-- translations/messages.fr.xlf--><trans-unitid="hVNhFLX"resname="navbar.home">  <source>Home</source>  <target>__navbar.home</target></trans-unit>

The command has options to specify locales, domains, and paths:

Description:  Update source tags with default locale targets in XLIFF files.Usage:  translation:update-xliff-sources [options] [--] [<paths>...]Arguments:  paths                    Paths to look for translations.Options:      --format=FORMAT      Override the default output format. [default: "xlf12"]      --domains[=DOMAINS]  Specify the domain to update. (multiple values allowed)      --locales=LOCALES    Specify the locale to update. (multiple values allowed)  -h, --help               Display help for the given command. When no command is given display help for the list command  -q, --quiet              Do not output any message  -V, --version            Display this application version      --ansi|--no-ansi     Force (or disable --no-ansi) ANSI output  -n, --no-interaction     Do not ask any interactive question  -e, --env=ENV            The Environment name. [default: "dev"]      --no-debug           Switch off debug mode.      --profile            Enables profiling (requires debug).  -v|vv|vvv, --verbose     Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debugHelp:  The translation:update-xliff-sources command updates the source tags in XLIFF files with the default locale translation if available.    You can specify directories to update in the command arguments:       php bin/console translation:update-xliff-sources path/to/dir path/to/another/dir    To restrict the updates to one or more locales, including the default locale itself, use the --locales option:      php bin/console translation:update-xliff-sources --locales en --locales fr    You can specify one or more domains to target with the --domains option. By default, all available domains for the targeted locales are used.      php bin/console translation:update-xliff-sources --domains messages

welcoMattic and cvergne reacted with heart emoji
@carsonbotcarsonbot added this to the7.1 milestoneJan 24, 2024
@squrioussqurious changed the titleAdd --update-source option in translation:extract[FrameworkBundle] [Translation] Add --update-source option in translation:extractJan 24, 2024
@squrioussquriousforce-pushed thetranslation/update-source-option-in-extract-command branch from5219f97 to708ab39CompareJanuary 24, 2024 17:04
@stof
Copy link
Member

Copying the default locale in the source tags of files for other locales should probably be done in a separate command thantranslation:extract as this is a different kind of change. This action would be doable for all keys that exist in the translation files, not only for keys that can be extracted from usages.

@squrioussqurious changed the title[FrameworkBundle] [Translation] Add --update-source option in translation:extract[FrameworkBundle] [Translation] Update XLIFF source tags with new translation:update-xliff-sources commandJan 25, 2024
@squrious
Copy link
ContributorAuthor

I created a dedicated command in the Translation component

@squrioussquriousforce-pushed thetranslation/update-source-option-in-extract-command branch from6095355 toefcfc4dCompareJanuary 25, 2024 16:56
@squrioussquriousforce-pushed thetranslation/update-source-option-in-extract-command branch fromefcfc4d to496b27aCompareMarch 18, 2024 09:50
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
Copy link
Member

@welcoMatticwelcoMattic left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks@squrious for this great work! I have 2 small comments about wording.
Otherwise your PR looks good to me 👍

Can you rebase your branch please?

$defaultLocaleCatalogue = $translatorBag->getCatalogue($this->defaultLocale);

if (!$defaultLocaleCatalogue instanceof MetadataAwareInterface) {
$io->error(sprintf('The default locale catalogue must implement "%s" to be used in this tool.', MetadataAwareInterface::class));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$io->error(sprintf('The default locale catalogue must implement "%s" to be used in thistool.', MetadataAwareInterface::class));
$io->error(sprintf('The default locale catalogue must implement "%s" to be used inbythiscommand.', MetadataAwareInterface::class));

$currentCatalogue = $translatorBag->getCatalogue($locale);

if (!$currentCatalogue instanceof MessageCatalogue) {
$io->warning(sprintf('The catalogue for locale "%s" must be an instance of "%s" to be used in this tool.', $locale, MessageCatalogue::class));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$io->warning(sprintf('The catalogue for locale "%s" must be an instance of "%s" to be usedin thistool.',$locale, MessageCatalogue::class));
$io->warning(sprintf('The catalogue for locale "%s" must be an instance of "%s" to be usedby thiscommand.',$locale, MessageCatalogue::class));

new InputOption('locales', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Specify the locale to update.', $this->enabledLocales),
])
->setHelp(<<<EOF
The <info>%command.name%</info> command updates the source tags in XLIFF files with the default locale translation if available.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The <info>%command.name%</info> command updates the source tags inXLIFF files with thedefaultlocaletranslation if available.
The <info>%command.name%</info> command updates the source tags inXLIFF files with thedefault translation localeif available.

?

Comment on lines 84 to 90
$format = $input->getOption('format');

if (!\array_key_exists($format, self::FORMATS)) {
$io->error(sprintf('Unknown format "%s". Available formats are: %s.', $format, implode(', ', array_map(fn ($f) => '"'.$f.'"', array_keys(self::FORMATS)))));

return self::INVALID;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we move this toinitialize method?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Not sure about that, I can't return any code from theinitialize method to indicate the option is invalid, so I would have to throw an exception instead.

I used the same logic as inTranslationUpdateCommand.

* file that was distributed with this source code.
*/

namespace Command;
Copy link
Contributor

Choose a reason for hiding this comment

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

namespace is wrong

welcoMattic reacted with eyes emoji
@squrioussquriousforce-pushed thetranslation/update-source-option-in-extract-command branch 2 times, most recently fromff77984 tof2c0cf4CompareSeptember 21, 2024 08:22
@squrious
Copy link
ContributorAuthor

Hello, I updated the PR according to your comments (not sure about the use ofinitialize to check command options though).

Also moved the changelog entry in the translation component to 7.2.

Low deps tests fail but I guess it's expected as the PR covers both framework bundle and translation component.

@squrioussquriousforce-pushed thetranslation/update-source-option-in-extract-command branch fromf2c0cf4 to5e27384CompareSeptember 21, 2024 08:32
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpot
Copy link
Member

Low deps tests fail but I guess it's expected as the PR covers both framework bundle and translation component.

To fix the low deps tests, you need to bump the required version of the component in the bundle.

@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@welcoMatticwelcoMatticwelcoMattic left review comments

@OskarStarkOskarStarkOskarStark left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

XLIFF export should contain default locale default texts in source tags
7 participants
@squrious@stof@fabpot@welcoMattic@OskarStark@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp