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
IntlExtension > Handle MissingResourceException #3257
Conversation
65fa22c
to
14efc95
Compare
14efc95
to
2df6814
Compare
Thank you @ruudk. |
This PR was submitted for the 3.x branch but it was merged into the 2.x branch instead (closes #3257). Discussion ---------- IntlExtension > Handle MissingResourceException When you want to get the language name of a language you can type: ```twig {{ inputLanguage | language_name }} ``` But if `inputLanguage` is not a valid language, a `MissingResourceException` is thrown, blowing up the whole page. Since in Twig, there is no way to catch this exception, it becomes extremely hard to work with these helpers if you have no control over the input. There is also no way to first check if the language exists before invoking the filter. Commits ------- 2df6814 IntlExtension > Handle MissingResourceException
@fabpot Thanks for the fast merge. Would it be possible to tag a new release? |
This should also be merged to the 3.x branch btw. |
Releases done :) |
@fabpot Thanks, quick question, I just deployed this to production and got some errors: {{ inputCountry | country_name('en') }} When
I think we should allow null as input, and return null? -public function getCountryName(string $country, string $locale = null): string
+public function getCountryName(?string $country, string $locale = null): ?string And then early return null when the input is null. Would you accept that? Then I will create a PR. |
I would always return a string, so an empty string when the input is null. |
This PR was submitted for the 3.x branch but it was merged into the 2.x branch instead. Discussion ---------- IntlExtension > Return empty string when input is null ```twig {{ inputCountry | country_name('en') }} ``` When `inputCountry` is `null` it will give this error: ``` Argument 1 passed to Twig\Extra\Intl\IntlExtension::getCountryName() must be of the type string, null given ``` With this change, an empty string will be returned instead. See discussion in #3257 (comment) Commits ------- caecd2a IntlExtension > Return empty string when input is null
When you want to get the language name of a language you can type:
But if
inputLanguage
is not a valid language, aMissingResourceException
is thrown, blowing up the whole page.Since in Twig, there is no way to catch this exception, it becomes extremely hard to work with these helpers if you have no control over the input. There is also no way to first check if the language exists before invoking the filter.