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
chore(i18n): Introduce Locale, Message, and MessageBundle #8028
Conversation
$this->markTestIncomplete(); | ||
} | ||
|
||
public function testDoesNotPerformSprintfFormattingIfArgsNotProvided() { |
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 test should give some idea of how I envision this all working together.
Eventually we will move most of the logic for loading the translation resources into a FilesystemMessageBundle class.
The approach LGTM |
62118c0
to
ed8b447
Compare
This should be ready for a final review before I pull it in. But if I don't hear back soon I'll just pull it in anyways as it is a private refactor that only adds classes/tests and doesn't change any runtime configuration/logic at all yet, plus I've already got an LGTM on the direction. |
* | ||
* @access private | ||
*/ | ||
abstract class 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.
Shouldn't this be a Template or MessageTemplate?
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, message template would be clearer.
My only concern here is how many objects we'd create/destroy translating a single page. Each translation constructs a new "en" Locale (that's easily optimized) but also a new SprintfMessage. |
This definitely assumes object creation is cheap, and is designed this way to allow mixing sprintf templates with ICU templates. We could optimize in 2.0 by removing the message objects entirely since we will only want to support ICU. |
But at the end of the day there is definitely the possibility of adding a few ms power request because of this change... |
There are some recent additions made to the translation class (like translation_key_exists). Those features are not yet added to these classes. Will you add those later? |
I need to update this PR with those improvements. |
da7b0e5
to
e382ecd
Compare
So the MessageBundle I think accomplishes what translation_key_exists wants, because you get just check if the return value of |
So this doesn't need anything else but a final review? |
These concepts will help us clean up the i18n code significantly.
That is correct |
Just posted several updates addressing all outstanding comments/todos, so PTAL and I will pull in after a couple LGTMs. Main thing to note here is that we are just introducing the classes, not even using them yet. |
LGTM |
chore(i18n): Introduce Locale, Message, and MessageBundle
These concepts will help us clean up the i18n code significantly.
TODO:
MessageBundle
so that it is essentiallyMap<Locale, Map<string, Message>>
__toString
handler onMessage
that outputs the template. This would allow us to avoid calling "format" with no arguments, making views a wee bit more terse: I.e.,{$message}
instead of{$message->format()}
Message
toMessageTemplate
template
protected instead of privateisset
checks with plain boolean checks where possible