-
Notifications
You must be signed in to change notification settings - Fork 98
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
MESDK-77 add @inlang/sdk/v2 with MessageBundle and related types #2700
Conversation
🦋 Changeset detectedLatest commit: b9eccb7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 29 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
inlang/source-code/versioned-interfaces/message-bundle/package.json
Outdated
Show resolved
Hide resolved
inlang/source-code/versioned-interfaces/message-bundle/README.md
Outdated
Show resolved
Hide resolved
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.
Wondering if releasing a v2 of @inlang/message
isn't better. Apps using the SDK now have name collisions:
import { Message } from "@inlang/sdk"
What message is imported here?
Recommendation:
- Release V2 prerelease of
@inlang/message
instead of having a new package - Suffix all types with V2 e.g.
MessageV2
,PatternV2
, etc. to avoid name collisions
(We will run into this problem again with a potential v3. Seems easier to then again suffix MessageV3
instead of having a new package and 3 potential name collisions)
inlang/source-code/versioned-interfaces/message-bundle/src/interface.ts
Outdated
Show resolved
Hide resolved
export type LocalDeclaration = Static<typeof InputDeclaration> | ||
export const LocalDeclaration = Type.Object({ | ||
type: Type.Literal("local"), | ||
name: Type.String(), | ||
value: Expression, | ||
}) |
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.
Do we need local declarations for v1?
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, we want to be able to import MF2 using this, right?
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 do we want to import MF2 for the MVP?
- nobody uses MF2
- let's ship only what we need to unblock apps namely (variants)
- ship in a way to make the data structure future proof
MF2 is still changing. anything we don't need i wouldn't introduce now
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.
Here still seems to be some unalignment. Let's achieve consensus @jldec @LorisSigrist @martin-lysk.
I wouldn't risk adding features from MF2 that apps don't need right now to support variants (pluralization, gendering) as they still change. I don't know why the need to import MF2 is recurringly coming up. We don't need to import MF2 just yet. Nobody uses MF2.
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 thought we needed to support formatting and markup features in inlang messages, and that local declarations are required to support patterns that embed modified (non-local) inputs. The local declaration defines how the input is modified instead of nesting functions inline in the pattern.
If we can do everything we need without locals, I'm happy to remove it.
@martin-lysk @LorisSigrist please let me know if you think this makes sense (or not) given what paraglide users have requested, or based on what you think you need for the paraglide compiler.
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.
Editing nested functions without locals also feels harder from UI/UX perspective, than doing it with locals. Do you agree @NilsJacobsen ?
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 would go step by step to enable pluralization first. Markup, for example, is unrelated to pluralization. But @jldec this will be your decision now. Being compatible with full MF2 from the get-go is in wrong IMO. The spec will change and we have different requirements because we have apps.
What is required for pluralization?
- MessageBundle
- Variants
- Pluralization function
Seems not to be required:
- Markup
- Other functions (like date formatting, gendering etc.)
- local declarations
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.
Sync notes https://linear.app/opral/issue/MESDK-77/requirements-for-gender-and-plurals#comment-0dd412be.
It seems like local declarations can be removed if we go the bottoms up approach. cc @martin-lysk
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.
👍 Removed for now.
|
||
export type VariableReference = Static<typeof VariableReference> | ||
export const VariableReference = Type.Object({ | ||
type: Type.Literal("variable"), |
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.
Mismatch between type name and type string VariableReference
vs variable
. Recommendation, follow MessageFormat PascalCase for all types:
-variable
+VariableRefernece
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 string "variable"
is from the MessageFormat 2.0 Data-model recommendation. Should we deviate?
https://github.com/unicode-org/message-format-wg/blob/6d7b4ba213e686ff2d403d3025d38d76b42b75f7/spec/data-model/README.md#expressions
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.
Oh wow, they deviated from the previous pattern then. I let @jldec decide. I prefer written out types it's a naming thing though which no real impact
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.
Let's keep this same as MF2 data model for now.
/** | ||
* A (text) element that is translatable and rendered to the UI. | ||
*/ | ||
export type Text = Static<typeof Text> | ||
export const Text = Type.Object({ | ||
type: Type.Literal("text"), | ||
value: Type.String(), | ||
}) |
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.
MessageFormat 2.0 seems to have removed the Text
type in favor of a pure string. What was their reasoning?
Notes from me:
- iterating through pattern elements seems much easier if every node has
node.type
property instead of using union matching e.g.if (typeof node === string || node.type === XYZ)
@samuelstroschein that' s a good catch! I was hoping that the new ideas:
|
|
@martin-lysk any opinion on this? |
@samuelstroschein ok - i'll add MessageBundleV2 and MessageV2 to sdk. |
correct. |
@samuelstroschein |
@@ -0,0 +1,122 @@ | |||
import { LanguageTag as Locale } from "@inlang/language-tag" |
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.
You can pull the Locale type into the types here.
- language tag has been it's own package to allow the community to use it
-- this is not happening - eases getting rid of versioned-interfaces
Introduces v2
MessageBundle
and related types, extracted from #2655Resolves opral/inlang-sdk#40
@inlang/sdk/v2
InlangProject
Usage
In case of type name conflicts with existing Message type
A message bundle is a collection of Messages which are based on a subset of ICU MessageFormat 2.
A bundle has an id (and optional aliases) which can be used to reference messages from UI code. Each message in the bundle targets a different locale.