-
Notifications
You must be signed in to change notification settings - Fork 30
runtime: add attribute formatting functionality in FluentLocalization #212
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: main
Are you sure you want to change the base?
Changes from 3 commits
4656173
226ee6b
076d05c
baebffa
b021959
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| from fluent.syntax import FluentParser | ||||||||||||||||||||
| from typing_extensions import NamedTuple | ||||||||||||||||||||
|
|
||||||||||||||||||||
| from .bundle import FluentBundle | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -22,6 +23,11 @@ | |||||||||||||||||||
| from .types import FluentType | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class FormattedMessage(NamedTuple): | ||||||||||||||||||||
| message: Union[str, None] | ||||||||||||||||||||
|
||||||||||||||||||||
| message: Union[str, None] | |
| value: Union[str, None] |
Outdated
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 something like this?
| for bundle in self._bundles(): | |
| if not bundle.has_message(msg_id): | |
| continue | |
| msg = bundle.get_message(msg_id) | |
| msg = next(( | |
| bundle.get_message(msg_id) | |
| for bundle in self._bundles() | |
| if bundle.has_message(msg_id) | |
| ), None) |
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.
The first reason is consistency, format_value also uses a for loop. The second reason is simplicity: the code looks linear and less bloated to those seeing it for the first time.
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 don't undertand how a for loop is more "linear" than what I suggest. Both methods end up looping through the bundles until they find a message; with my recommendation you get to lose one level of nesting.
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.
Okay, then let's do this for both methods mentioned above
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 use the base version from
typing?