-
-
Notifications
You must be signed in to change notification settings - Fork 40
New feature: Translation message placeholder support #121
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: 2.27.x
Are you sure you want to change the base?
Changes from 12 commits
2c08407
7268f05
3f9c7c9
feac441
7d257af
f07eef4
feee260
1306a09
1c50b03
de5e914
48a9044
7ca402c
5c4f32d
da1f695
25ca826
2e27540
a9cc082
58bf694
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 |
|---|---|---|
|
|
@@ -52,9 +52,10 @@ public function getDependencyConfig() | |
| Geography\CountryCodeListInterface::class => Geography\DefaultCountryCodeList::class, | ||
| ], | ||
| 'factories' => [ | ||
| Translator\TranslatorInterface::class => Translator\TranslatorServiceFactory::class, | ||
| Translator\LoaderPluginManager::class => Translator\LoaderPluginManagerFactory::class, | ||
| Geography\DefaultCountryCodeList::class => [Geography\DefaultCountryCodeList::class, 'create'], | ||
| Translator\TranslatorInterface::class => Translator\TranslatorServiceFactory::class, | ||
| Translator\LoaderPluginManager::class => Translator\LoaderPluginManagerFactory::class, | ||
| Translator\PlaceholderPluginManager::class => Translator\PlaceholderPluginManagerFactory::class, | ||
| Geography\DefaultCountryCodeList::class => [Geography\DefaultCountryCodeList::class, 'create'], | ||
| ], | ||
| ]; | ||
| } | ||
|
|
@@ -159,23 +160,25 @@ public function getViewHelperConfig() | |
| { | ||
| return [ | ||
| 'aliases' => [ | ||
| 'countryCodeDataList' => View\Helper\CountryCodeDataList::class, | ||
| 'currencyformat' => View\Helper\CurrencyFormat::class, | ||
| 'currencyFormat' => View\Helper\CurrencyFormat::class, | ||
| 'CurrencyFormat' => View\Helper\CurrencyFormat::class, | ||
| 'dateformat' => View\Helper\DateFormat::class, | ||
| 'dateFormat' => View\Helper\DateFormat::class, | ||
| 'DateFormat' => View\Helper\DateFormat::class, | ||
| 'numberformat' => View\Helper\NumberFormat::class, | ||
| 'numberFormat' => View\Helper\NumberFormat::class, | ||
| 'NumberFormat' => View\Helper\NumberFormat::class, | ||
| 'plural' => View\Helper\Plural::class, | ||
| 'Plural' => View\Helper\Plural::class, | ||
| 'translate' => View\Helper\Translate::class, | ||
| 'Translate' => View\Helper\Translate::class, | ||
| 'translateplural' => View\Helper\TranslatePlural::class, | ||
| 'translatePlural' => View\Helper\TranslatePlural::class, | ||
| 'TranslatePlural' => View\Helper\TranslatePlural::class, | ||
| 'countryCodeDataList' => View\Helper\CountryCodeDataList::class, | ||
| 'currencyformat' => View\Helper\CurrencyFormat::class, | ||
| 'currencyFormat' => View\Helper\CurrencyFormat::class, | ||
| 'CurrencyFormat' => View\Helper\CurrencyFormat::class, | ||
| 'dateformat' => View\Helper\DateFormat::class, | ||
| 'dateFormat' => View\Helper\DateFormat::class, | ||
| 'DateFormat' => View\Helper\DateFormat::class, | ||
| 'numberformat' => View\Helper\NumberFormat::class, | ||
| 'numberFormat' => View\Helper\NumberFormat::class, | ||
| 'NumberFormat' => View\Helper\NumberFormat::class, | ||
| 'plural' => View\Helper\Plural::class, | ||
| 'Plural' => View\Helper\Plural::class, | ||
| 'translate' => View\Helper\Translate::class, | ||
| 'Translate' => View\Helper\Translate::class, | ||
| 'translateplural' => View\Helper\TranslatePlural::class, | ||
| 'translatePlural' => View\Helper\TranslatePlural::class, | ||
| 'TranslatePlural' => View\Helper\TranslatePlural::class, | ||
| 'translateWithParams' => View\Helper\TranslateWithParams::class, | ||
| 'translatePluralWithParams' => View\Helper\TranslatePluralWithParams::class, | ||
|
|
||
| // Legacy Zend Framework aliases | ||
| 'Zend\I18n\View\Helper\CurrencyFormat' => View\Helper\CurrencyFormat::class, | ||
|
|
@@ -186,13 +189,15 @@ public function getViewHelperConfig() | |
| 'Zend\I18n\View\Helper\TranslatePlural' => View\Helper\TranslatePlural::class, | ||
| ], | ||
| 'factories' => [ | ||
| View\Helper\CountryCodeDataList::class => View\Helper\Container\CountryCodeDataListFactory::class, | ||
| View\Helper\CurrencyFormat::class => InvokableFactory::class, | ||
| View\Helper\DateFormat::class => InvokableFactory::class, | ||
| View\Helper\NumberFormat::class => InvokableFactory::class, | ||
| View\Helper\Plural::class => InvokableFactory::class, | ||
| View\Helper\Translate::class => InvokableFactory::class, | ||
| View\Helper\TranslatePlural::class => InvokableFactory::class, | ||
| View\Helper\CountryCodeDataList::class => View\Helper\Container\CountryCodeDataListFactory::class, | ||
| View\Helper\CurrencyFormat::class => InvokableFactory::class, | ||
| View\Helper\DateFormat::class => InvokableFactory::class, | ||
| View\Helper\NumberFormat::class => InvokableFactory::class, | ||
| View\Helper\Plural::class => InvokableFactory::class, | ||
| View\Helper\Translate::class => InvokableFactory::class, | ||
| View\Helper\TranslatePlural::class => InvokableFactory::class, | ||
| View\Helper\TranslateWithParams::class => InvokableFactory::class, | ||
| View\Helper\TranslatePluralWithParams::class => InvokableFactory::class, | ||
|
Comment on lines
+198
to
+199
Member
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 will provide the delegator to add the decorator for the new view helpers.
Author
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. Thank you, I was going to ask regarding that. That would be great. |
||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Laminas\I18n\Translator\Placeholder; | ||
|
|
||
| use function str_replace; | ||
|
|
||
| class HandlebarPlaceholder implements PlaceholderInterface | ||
|
Member
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. The naming is still wrong because it is an formatter which formats a message. A placeholder is in the message: "Hello {name}!" – here
Author
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. @froschdesign so then from this, shall i rename things like this:
or, if you have something else in mind, please advise |
||
| { | ||
| public function compile(string $locale, string $message, iterable $placeholders = []): string | ||
| { | ||
| $compiled = $message; | ||
| foreach ($placeholders as $key => $value) { | ||
| $compiled = str_replace("{{{$key}}}", $value, $compiled); | ||
| } | ||
|
|
||
| return $compiled; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.