Skip to content

Parameterized Messages #258

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

Closed
eemeli opened this issue Apr 19, 2019 · 2 comments
Closed

Parameterized Messages #258

eemeli opened this issue Apr 19, 2019 · 2 comments
Labels

Comments

@eemeli
Copy link
Member

eemeli commented Apr 19, 2019

Reading through the BNF, I was surprised by this:

fluent/spec/fluent.ebnf

Lines 67 to 68 in aa89b97

MessageReference ::= Identifier AttributeAccessor?
TermReference ::= "-" Identifier AttributeAccessor? CallArguments?

Having then read through some of the history (In particular #176 and this comment on #80), I think I sort of understand the reasoning here, but I believe in actual use it could still prove rather surprising.

The usage pattern I have in mind here is first implementing a parameterised term, and later having a need for using that term directly as a message. In that situation, replacing -term with term in messages won't work, as {term(foo:"bar")} is not valid syntax.

If there's a longer-term intent of differentiating the capabilities of terms and messages more, then this difference makes sense. As is it seems to be the only thing that you can do with a term but not with a message, and that's a bit odd.

@stasm
Copy link
Contributor

stasm commented Apr 19, 2019

Thanks for an in-depth look into the EBNF :)

Terms are meant to be private and stay private, so changing -term to term isn't something I'd recommend doing. You'd need to update all references across all messages, which would be disruptive. In Mozilla localizations, we solve the problem you described by creating a new message which simply references the term.

The primary use-case is to allow localizers to define glossary terms. Take the following Italian example:

-sync-brand-name = {$capitalization ->
   *[uppercase] Account Firefox
    [lowercase] account Firefox
}

sync-dialog-title = {-sync-brand-name}
sync-signedout-account-title =
    Connetti il tuo {-sync-brand-name(capitalization: "lowercase")}

Thanks to the term being private and impossible to reference from the outside of the file, the localizer is in total control of it. If they decide to change the default variant to the lowercase one, they are certain that no UI references the term directly. If they consequently update all references in their translations (which they control, too), everything will continue to work as expected:

-sync-brand-name = {$capitalization ->
    [uppercase] Account Firefox
   *[lowercase] account Firefox
}

sync-dialog-title = {-sync-brand-name(capitalization: "uppercase")}
sync-signedout-account-title =
    Connetti il tuo {-sync-brand-name)}

In both scenarios, calling sync-dialog-title from the code gives the uppercase variant, Account Firefox.

Let me know what you think about this. Perhaps this is more of a documentation issue? https://projectfluent.org/fluent/guide/terms.html could do a better job of explaining the reasoning behind terms being private.

@eemeli
Copy link
Member Author

eemeli commented Apr 19, 2019

That makes sense. The particular point that I was missing (and which could be improved in the documentation) was that terms are explicitly controlled by the localizer.

One aspect of Fluent that I'm starting to like is that it's got thought put into its use from the localizer's point of view, separately from the developer, and that it's opinionated about the scope of the solutions it's covering. In particular, fixing the file format makes a lot of sense, as it's something that e.g. ICU MessageFormat leaves out of its scope.

@stasm stasm added the docs label Apr 23, 2019
@eemeli eemeli closed this as completed Jun 9, 2019
null2264 added a commit to ZiRO-Bot/Z3R0 that referenced this issue Mar 20, 2023
I have no idea if this is a good practice, but I do find a GitHub
issue related to this.

REF: projectfluent/fluent#258
null2264 added a commit to ZiRO-Bot/Z3R0 that referenced this issue Apr 16, 2023
* feat: Experimental i18n

* chore: Add missing license header

* refactor: Use fluent.runtime internal API

* feat: Testing i18n inside the bot

* feat: Test with different language

* feat: Add different way to set locale

* test: Further i18n testing

* docs: Remove i18n from TODO [skip ci]

* feat: List out every locales on init
Should allow the bot the get accurate list of available locales

* feat: Use the i18n on the bot

* refactor(i18n): Better typehint support

* fix: Don't use isolating in FluentBundle

* test: Handle i18n in tests

* chore: Turn i18n into async

* docs: README

* feat: Support slash

* fix(i18n): Default command name

* chore: Update fluent

* fix: Handle locale_str in help command

* chore: Change `brief` -> `description`, `description` -> `help`
This will help supporting i18n easier since AppCommands only has
short description and has no such thing as brief and long description

* locale: Fix inconsistent command name

* fix: Wrong locale code

* feat(i18n): Shortcuts for locale_str in Context

* locale: Fix another inconsistency

* locale: (Partially) translated `exts.admin`

* locale: Improve id translation

* locale: (Partially) translated anilist

* locale: Translate admin commands' arguments

* locale: (Partially) translated fun

* locale: (Partially) translated info

* locale: (Partially) translated meta

* locale: Translated NSFW

* locale: (Partially) translated timer

* locale: (Partially) translated utilities

* fix: Invalid locale message id

* fix: Typo

* feat: Custom `@command` and `@group` decorator

* locale: Japanese

* locale: Translated log config handler
I have no idea if this is a good practice, but I do find a GitHub
issue related to this.

REF: projectfluent/fluent#258

* feat: WIP i18n friendly embed builder

* feat: WIP i18n-compatible Embed Builder

* locale: Translated admin

* fix: Fix locale

* fix: Role set title use the wrong locale key

* locale: Translated anilist

* fix: Cog page still use short_doc instead of description

* fix: Flag raise error

* locale: Translate fun

* fix: Reddit colour is not used in loading message

* locale: Translate coin flip

* locale: Add missing translation and fix error

* locale: Translate info

* fix: Brain fart, should be 'result =' not 'return'

* locale: Remove ERROR prefix

* locale: Remove ERROR prefix

* locale: Translate meta

* fix: Quick embed fields

* locale: Translate the rest of the commands

* fix: Embed fields become singleton for some reason

* fix: Invalid message id

* test: Fix test unit

* fix: Open ftl files with utf8 encoding

* feat: Port ZEmbed shortcuts to ZEmbedBuilder

* chore: Simplify admin codes

* chore: Stop pyright from yelling me about property setter

* chore: Merge greeting properly

* fix: Extension load/reload doesn't work

* fix: Duplicate function

* chore: Add `Users` model and add locale column to `GuildConfigs` model

* docs: Accidentally revert README.md changes

* chore: Improve typehint

* docs: i18n update

* revert: Revert "chore: Improve typehint"

This reverts commit 0fd838f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants