-
Notifications
You must be signed in to change notification settings - Fork 27
AttributeError: 'FluentBundle' object has no attribute 'add_messages' #135
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
Comments
I'm also now very confused about this "pre-release" marker visible on the GitHub release page. These version have been released to PyPI as "0.2.0", "0.3.0" etc. so I don't understand how they can be described as pre-release, there is nothing in even the version number to indicate it is a pre-release. @Pike @stasm why have these been put on PyPI without the docs being updated? |
Sorry about this. We're more and more invested in Fluent and we've been migrating more and more of Firefox to it (see https://arewefluentyet.com). Over the last few months we've focused primarily on the JavaScript and Rust implementations, however, and this has resulted in this unfortunate situation when The good news is that we're planning to start using @Pike is away this week. He's been more involved in |
Thanks for the reply @stasm! That makes me much more confident that this will be actively maintained. Until the docs can be updated, do you know by chance what is the expected way to invoke fluent right now? I have this in python 3: from fluent.runtime import FluentBundle, FluentResource
resource = """
-brand-name = TheApp
welcome-to-the-app = Welcome to { -brand-name }!
"""
bundle = FluentBundle(['en-US'])
bundle.add_resource(FluentResource(resource))
# 🤔🤔🤔
translated_string, warnings = bundle.format_pattern(bundle.get_message('welcome-to-the-app').value)
print(translated_string) In addition to being a pretty awkward interface, that outputs two mysterious unicode characters: The two square characters can't be pasted into the github comment box, but you can print the same thing by doing this:
Any thoughts? Thanks in advance. |
Those are FSI/PDI - unicode directionality reset characters. They notify layout that the content of the inner part may be of different directionality than the outer text. For example an Arabic name in an English string etc. You can read more about it here: https://github.com/projectfluent/fluent/wiki/BiDi-in-Fluent#syntax |
Interesting @zbraniecki thanks for that explanation. It makes sense to me that this is necessary sometimes, if you're combining ltr/rtl strings. Possibly dumb question though: don't we often know when the placeable text has the same directionality as the target language? In those cases do we need these characters? My more practical concern is that I've only tested the string output in a couple places (bash, unit tests, console output in python), and in each case the handling of these characters is not great. It would be nice if I didn't have to worry whether every email/sms/push/etc. my app sends is going to show unicode ☐mysteryboxes☐ to end-users. Maybe there's no easy way to get around this though? |
The assumption is that in most cases you're providing variables that come from an unknown source - either user provided (name) which may be of either directionality, or a known directionality to any locale (so, both to ltr and rtl).
If both source and variable locale is known, we could avoid that. There's an idea to do sth like: from fluent.runtime import FluentBundle, FluentResource
resource = """
welcome-to-the-app = Welcome to { $foo }!
"""
bundle = FluentBundle(['en-US'])
bundle.add_resource(FluentResource(resource))
msg = bundle.get_message('welcome-to-the-app')
translated_string, warnings = bundle.format_pattern(msg.value, {
'foo': FluentString('Jane', dir="ltr")
})
print(translated_string) and in that case we could skip injecting directionality separators for ltr locales. But this hasn't materialize yet.
Yeah, we tested it in the Web environment and modern layout engines usually support Unicode and in result support FSI/PDI. For unit tests, two thoughts:
translated_string, warnings = bundle.format_pattern(msg.value, { 'foo': 'Jane' })
assert_eq(translated_string.contains("Jane"), true)
assert_eq(len(warnings), 0) over trying to test exact output.
|
Python 3 console seems to handle bidi chars for me quite well:
|
Your example is correct, I'd just add an from fluent.runtime import FluentBundle, FluentResource
resource = FluentResource("""
-brand-name = TheApp
welcome-to-the-app = Welcome to { -brand-name }!
""")
bundle = FluentBundle(['en-US'])
bundle.add_resource(resource)
message = bundle.get_message('welcome-to-the-app')
if message.value is not None:
translated_string, warnings = bundle.format_pattern(message.value)
print(translated_string) Obviously, in the example above the guard is not really required, since we know that The API is a bit verbose on purpose. It's supposed to be a low-level API on top of which easier-to-use abstractions can be built which suit the needs of the app. Some discussion about it can be found on the Discourse and in the PR implementing the API in fluent.js. |
Hey @zbraniecki @stasm thank you both for the thoughtful replies. Some quick responses:
I like that idea. It would be great if you could also specify the direction in the messages file so that you could declare your brand name once, translate it in some languages, and still have it get proper treatment everywhere in the app while still dodging the bidi markers where they're not doing anything because all the text is in the same direction. This of course assumes still that we can't usually tell which direction the arg text is supposed to be in and do this automatically, which I'm still not fully convinced about, but also too ill-informed to argue properly. It seems like if you have Arabic/Farsi/Hebrew/etc. characters you must know basically 100% of the time it should be written RTL. So there must be some other edge case that I don't understand where you can't tell the direction of a user-provided string and so have to always insert the BIDI markers, as opposed to only inserting them when you know the direction switches.
Got it, and the bidi markers are definitely invisible in a couple places for me as well. The specific areas I've had trouble with the bidi characters were inside the python console that's nested in PyCharm (where I get boxes) and in bash on ubuntu 18.04 (where I'm unable to fully delete a line which includes those characters). Both support unicode quite well in every case I've seen except this one. This could be a unicode version issue or just an issue with various implementations of unicode, but in either case my main point is there is some tooling "cost" involved for anyone who wants to start using Fluent, where clearly lots of tools do not yet understand what to do with the bidi markers. If you can "postpone" that cost for people who are doing simple stuff until they start mixing language directions, you can probably help increase the number of people who will use Fluent.
Makes sense. And I'm definitely a fan of exposing a low-level API and keeping it consistent so people can do complicated things when needed. In this case, though, why not also expose a couple of higher level methods which do the simple thing? Because gettext, which I dislike deeply, beats Fluent hands down when it comes to the API for the simplest possible case:
In Fluent you could just as easily do the something as simple (and much simpler in the plural and arg cases):
And all it would take is a few lines so that every user doesn't have to reinvent things:
As a bonus, you avoid hundreds of duplicate questions from people like me showing up and asking the same question about how to actually implement Fluent. 😉 |
This is a good idea. I think it would be best to expose these higher level methods on something higher up than We've been thinking of standardizing the high-level abstraction (called |
There are a couple of things here. For one, @spookylukey is the only one on rtd that has access, and is involved here. The Pike over there isn't me. (I'm DrAxelHecht on rtd.) Luke, could you add me and remove that other Pike? Thanks. The other is that we haven't merged the next-gen-api branch to master yet. Now that Luke gave his OK in https://discourse.mozilla.org/t/experimental-release-of-python-fluent-runtime/47569, we should get that done quickly. The new docs themselves are written, you can get a sneak peek on https://github.com/projectfluent/python-fluent/blob/next-gen-api/fluent.runtime/docs/usage.rst. Note that that highlights the new API around the Happy to follow up on the other topics raised here on discourse. |
Done! |
OK, I've updated the configuration here for the webhook to work again, and rebuilt the docs based on master. The next-gen-api branch is merged, too, so the docs now reflect what's on pypi. As I mentioned, the other comments are better suited for discourse, so I'm closing this out. |
I'm shopping around for gettext replacements. Is the python fluent client (and fluent more broadly) still being maintained?
I mainly ask because even the happy path described in the docs does not work properly right now:
Looks like it was yanked out in the 0.3.0 "pre-release" and the docs weren't updated.
Anyway, Fluent seems cool, but I'd rather not go through the heartache of using it only to learn in 6 months that Mozilla has abandoned it. Thanks for any insight you have!
The text was updated successfully, but these errors were encountered: