-
Notifications
You must be signed in to change notification settings - Fork 45
Semantic Comments Proposal: Variables #140
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'd love to see this, and it would be especially helpful for elm-fluent - which has recently reached a stage where it is usable in production. elm-fluent might also be interesting to you as:
elm-fluent works differently from most other implementations as it operates as a compiler that converts However, the static typing is a challenge in some cases, because the Fluent spec kind of assumes dynamic typing. For numbers, elm-fluent is able to infer a numeric type if It would be nice if we could explicitly state the type in a semantic comment. In addition, there are other ways which I'd love to be able to use Elm's static typing. For example, some variables are essentially enums e.g. a user gender might be For example, adapting your suggestion, you could do:
Implementations that don't benefit from enums will interpret this as just a string, optionally validating the value. elm-fluent would generate or somehow locate a enum type that can literally only be |
+1 to the proposal and the strongly typed tooling use case. Enum syntax bikeshed: TypeScript has string literal types (e.g.
That starts opening the door on the
Or, maybe that should be spelled with a dedicated keyword:
Or, maybe the user can omit the type to get
My vote: even though my heart is in the strict static typed world, fluent's origins are weakly typed. Let the user omit type info and the implicit behavior will be |
@spookylukey:
Could you not infer the enum types from the variants themselves? So rather than copying the variants to the semantic comment, you'd generate it based on the variants in the selector. Then the type in the comment could either be The set of variants can vary between languages, but I imagine you could just take the set of all languages' enum options when exposing the top-level module. Am I missing something? Are you thinking more in terms of communication from developers to localizers, while I'm thinking more in terms of communication from localizers to developers? |
@miniyou Parsing that info from the FTL would be very complicated because not all language will have the same variants. You would need to parse and combine results from every one of your languages to be meaningful, and even then it would be an awkward workflow to require finished translation before your app understand its own variable types. I'm not sure semantic comments make the workflow less awkward, but this isn't an easy problem. |
I think this discussion would be a great fit for https://discourse.mozilla.org/c/fluent. Mostly, because it's actually a discussion, and also because I am confident that variables are just a small part of the problem you're facing, and I'd rather not derail this issue more. |
This is part of the series of proposals spanning out of the meta #16.
Variables
One of the core elements of the Fluent ecosystem is a model of passing a set of variables from the developer to localizer enabling the localizer to augument their translation.
Establishing a semantic way of describing the variables available to the localizer would help localization tools, checks and localizers themselves better understand the context in which they operate.
It would be especially beneficial for Rich Editor in Pontoon to provide better UX when operating on variables, and for checks to be able to raise warnings on misuse of the variables.
Variables can be considered part of #139, but they're such a core feature that I'd like to discuss them separately for two reasons:
First, being the most common and omnipresent example of a semantic information they should drive the whole conversation and we should design the meta-information model specifically taking into account this use case over others.
Secondly, because they're so dominant, we may want to consider separating them out of meta information and providing further syntax sugar to make them easier to work with.
So, as part of meta-information they could be represented as:
but since we know that
$
sygil denotes a variable, we may want to provide additional syntax sugar to reduce the visual clutter:It then could be visually represented in Pontoon as:
and linters would be able to determine use and misuse of variables and warn about unused variables if needed.
The text was updated successfully, but these errors were encountered: