-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
[Translator] Add "by-domain" translation dumper #1927
base: 2.x
Are you sure you want to change the base?
[Translator] Add "by-domain" translation dumper #1927
Conversation
683c1ec
to
79f0a13
Compare
$webpackDumperDefinition = $container->getDefinition('ux.translator.translations_dumper.webpack'); | ||
$webpackDumperDefinition->setArgument(0, $config['dump_directory']); | ||
|
||
$assetMapperDumperDefinition = $container->getDefinition('ux.translator.translations_dumper.asset_mapper'); | ||
// Setting to the default value because the folder isn't configurable with asset mapper | ||
$assetMapperDumperDefinition->setArgument(0, $this->processConfiguration($configuration, [])['dump_directory']); |
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 we should use some configuration for the user to chose which service he wants to use..
... and alias it as "TranslationDumper".
$domainSplit[$domainFileName] ??= []; | ||
$domainSplit[$domainFileName][$translationId] ??= ['id' => $translationId, 'translations' => []]; | ||
$domainSplit[$domainFileName][$translationId]['translations'][$domain] ??= []; | ||
$domainSplit[$domainFileName][$translationId]['translations'][$domain][$locale] = $translationDetails['message']; |
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.
So you'd keep all the locale in one file ?
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.
Yes that's the plan right now, otherwise we'd have to import too many modules (1 per combination of domain/locale). Though a filter on the dumped locales could help remove the unnecessary ones. Unless you have something else in mind ?
if (\in_array($domain, $this->excludedDomains, true)) { | ||
continue; | ||
} | ||
if (0 !== \count($this->domains) && !\in_array($domain, $this->domains, true)) { | ||
continue; | ||
} |
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 we maybe should use "includedDomain" / "excludedDomain" or something similar, maybe just me but the difference in naming makes it less clear
$this->filesystem->dumpFile($this->dumpDir.'/configuration.js', sprintf( | ||
"export const localeFallbacks = %s;\n", | ||
json_encode($this->getLocaleFallbacks(...$catalogues), \JSON_THROW_ON_ERROR) | ||
)); |
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.
Maybe a simple concatenation here ?
$this->filesystem->dumpFile($this->dumpDir.'/configuration.d.ts', <<<'TS' | ||
import { LocaleType } from '@symfony/ux-translator'; | ||
|
||
export declare const localeFallbacks: Record<LocaleType, LocaleType>; | ||
TS | ||
); |
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.
Is this file static ?
} | ||
|
||
public function setExcludedDomains(array $domains = []): void | ||
{ | ||
$this->excludedDomains = $domains; | ||
} | ||
|
||
public function setDomains(array $domains): void | ||
{ | ||
$this->domains = $domains; | ||
} |
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.
Wondering if this should either
- be in an abstractDumper
- be in a new TranslationDumpProvider (find a better name^^)
Because there is a certain amount of duplicated code there
"translations": { | ||
"foobar": { |
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.
is this "domain as key" necessary ?
function resetRegisteredDomains() { | ||
_registeredTranslations = {}; | ||
} |
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.
What is the use case ?
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.
It was mainly to reset the translations between tests, but I changed the behavior to allow overriding already registered translations, so I got rid of this method.
@@ -30,8 +30,11 @@ | |||
* @phpstan-type Locale string | |||
* @phpstan-type MessageId string | |||
*/ | |||
class TranslationsDumper |
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.
This would be a massive BC break... not sure the "experimental" would be enough :)
Maybe should we keep it as alias / deprecated ?
@kbond ?
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.
What about keeping the TranslationDumper as a wrapper that would call either or both the Webpack and AssetMapper dumper + the config dumper ?
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.
Why not ! That could reduce some code duplication too!
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.
Hi, and thanks for your contribution! :)
I didn't look for everything, but isn't there too much things for a single PR?
I see dump per domains, global domains filters, but also a new dumper for AssetMapper... is it too much?
Hi, I thought indeed about making two PRs : one for the filtering and another one for the 'per-domain' dump (which is what the AssetMapperDumper does, there won't be any change on the actual webpack-oriented behavior). I made it in one PR because it all came from the same issue, but I can still split the PR if need be. |
d0b0305
to
a370cb7
Compare
a370cb7
to
108ed58
Compare
e0be201
to
9e3f254
Compare
Hi @maelanleborgne : do you need anything on this one ? |
Will follow #1930
registerDomain(domain)
js function, and accessed using the existingtrans
function by passing the translation key as a first argument.TODO: