-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Add icu message support for the lokalise provider #45368
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
base: 5.4
Are you sure you want to change the base?
Changes from all commits
d8a15cf
375cc98
7a6b771
1607e56
2603a21
967df36
692f87a
33041a6
4167b96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -37,14 +37,16 @@ final class LokaliseProvider implements ProviderInterface | |||||||
private $logger; | ||||||||
private $defaultLocale; | ||||||||
private $endpoint; | ||||||||
private $intlIcuEnabled; | ||||||||
|
||||||||
public function __construct(HttpClientInterface $client, LoaderInterface $loader, LoggerInterface $logger, string $defaultLocale, string $endpoint) | ||||||||
public function __construct(HttpClientInterface $client, LoaderInterface $loader, LoggerInterface $logger, string $defaultLocale, string $endpoint, bool $intlIcuEnabled = false) | ||||||||
{ | ||||||||
$this->client = $client; | ||||||||
$this->loader = $loader; | ||||||||
$this->logger = $logger; | ||||||||
$this->defaultLocale = $defaultLocale; | ||||||||
$this->endpoint = $endpoint; | ||||||||
$this->intlIcuEnabled = $intlIcuEnabled; | ||||||||
} | ||||||||
|
||||||||
public function __toString(): string | ||||||||
|
@@ -102,7 +104,12 @@ public function read(array $domains, array $locales): TranslatorBag | |||||||
|
||||||||
foreach ($translations as $locale => $files) { | ||||||||
foreach ($files as $filename => $content) { | ||||||||
$translatorBag->addCatalogue($this->loader->load($content['content'], $locale, str_replace('.xliff', '', $filename))); | ||||||||
$domain = str_replace('.xliff', '', $filename); | ||||||||
if ($this->intlIcuEnabled) { | ||||||||
$domain .= MessageCatalogueInterface::INTL_DOMAIN_SUFFIX; | ||||||||
} | ||||||||
|
||||||||
$translatorBag->addCatalogue($this->loader->load($content['content'], $locale, $domain)); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
@@ -149,6 +156,7 @@ private function exportFiles(array $locales, array $domains): array | |||||||
'filter_langs' => array_values($locales), | ||||||||
'filter_filenames' => array_map([$this, 'getLokaliseFilenameFromDomain'], $domains), | ||||||||
'export_empty_as' => 'skip', | ||||||||
'placeholder_format' => $this->intlIcuEnabled ? 'icu' : 'symfony', | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
A different parameter is required to ensure that the plurals are also in the expected ICU format. The param is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this change, you will still get plurals in the old format from Lokalise, which the Symfony Translator is not expecting in ICU files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be really weird behaviour IMHO, but better safe then sorry i guess :D Could you verify this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's weird, but I guess @TwanVermeulen is right. According to the documentation https://developers.lokalise.com/reference/api-plurals-and-placeholders#plural-format-descriptions I guess we have to pass both parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add it, but as i said - cant really verify for now as I'm not working anymore on the project which needed this patch. So is this verified that this is needed and working? |
||||||||
], | ||||||||
]); | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to name it short.