Skip to content

[FrameworkBundle][Translation][TwigBridge] Add option to extract blank messages #45772

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 1 commit into from
Closed

[FrameworkBundle][Translation][TwigBridge] Add option to extract blank messages #45772

wants to merge 1 commit into from

Conversation

gndk
Copy link
Contributor

@gndk gndk commented Mar 17, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR symfony/symfony-docs#16621

Currently, new messages are extracted as a prefixed copy of the key ("foo" -> "__foo") when using the translation:extract command.

With his PR I propose a --blank option that would extract new messages as blank strings ("foo" -> "").

This allows for smoother workflows with translation providers like Loco, Lokalise or CrowdIn, because by some of them the prefixed copy is considered translated, while blank strings are considered untranslated.

The result is that you currently have 100% translation progress immediately after translation:push, even if none of the translation keys are actually translated. This makes working with hundreds or thousands of translation keys or general collaboration through these tools unnecessarily hard.

For example lets say you have 1000 translation keys in your application and want to add a new locale. You extract and push them to the provider. Then you or some translator starts work on them. They won't finish all keys in one session, but instead maybe finish 100 of them and continue work the next day. However, because all the messages already have the "translated" status, its hard to know where to continue. You have to look at every single message again and determine if it is really translated, or if the strings are just technically different.

It is very easy to miss untranslated messages if all of them have a green checkmark, regardless of the real translation status.

The benefit of pushing blank strings as translation messages is that it allows you to easily filter for untranslated messages as a "todo list", instead of checking each message manually for its translation status.

@carsonbot carsonbot added this to the 6.1 milestone Mar 17, 2022
@carsonbot carsonbot changed the title [FrameworkBundle] [Translation] [TwigBridge] Add option to extract blank messages [FrameworkBundle][Translation][TwigBridge] Add option to extract blank messages Mar 17, 2022
@gndk
Copy link
Contributor Author

gndk commented Mar 17, 2022

Psalm fail seems unrelated as I see the same error in other PRs. AppVeyor timeout.

@gndk
Copy link
Contributor Author

gndk commented Mar 18, 2022

Pinging @Nyholm, because you agreed in my previous PR that this is a problem worth solving 🙂 .

@carsonbot
Copy link

Hey!

I think @natewiebe13 has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@welcoMattic
Copy link
Member

@gndk great work, thank you! Could you please rebase your branch and address the 2 quick comments? Thanks 👍

Comment on lines +156 to +161
if (!method_exists($this->extractor, 'blank') && true === $input->getOption('blank')) {
$errorIo->error('The --blank option is not supported by this extractor. It is available in symfony/translation 6.1 and symfony/twig-bridge 6.1.');

return 1;
}

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 added the error message up here because other checks like this also live here. And I don't need to pass the OutputInterface down to the method. Seems cleaner this way.

Not sure about the wording of the message. Anything you want to change or add?

…k messages

Extract new-found messages as blank strings instead of
a prefixed copy of the translation key when using
the blank option for the translation:extract command.

This allows for a smoother workflow when using third
party translation providers, because empty strings
are considered “untranslated”, while an exact copy of
the translation key is considered “translated”.
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

The proposed method is a setter. This makes the extractor services mutable. We'd really better avoid that.
Does it really make sense to have a command line option for this? Isn't setting messages as empty a project-wide setting? If yes, then we'd better go with a config option and a constructor argument.

@welcoMattic
Copy link
Member

@nicolas-grekas is right, we should avoid mutable services, I missed it. 👍 for config option.

@gndk
Copy link
Contributor Author

gndk commented Apr 12, 2022

Ok, I will turn it into a config option instead 👍 . Don't have time this week, so will be done after the easter weekend.

@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@nicolas-grekas
Copy link
Member

Friendly ping @gndk

@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@gndk gndk closed this by deleting the head repository Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants