Skip to content
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

Localization Language Feature #618

Merged
merged 23 commits into from
Sep 17, 2023
Merged

Localization Language Feature #618

merged 23 commits into from
Sep 17, 2023

Conversation

gdotdesign
Copy link
Member

This PR adds language features for handling localizations: https://github.com/mint-lang/mint/blob/locales/documentation/Language/Locale.md

@gdotdesign gdotdesign requested a review from Sija June 26, 2023 13:52
@gdotdesign gdotdesign self-assigned this Jun 26, 2023
@gdotdesign gdotdesign added the language Language feature label Jun 26, 2023
@gdotdesign gdotdesign added this to the 0.19.0 milestone Jun 26, 2023
Base automatically changed from semantic-tokens to master July 19, 2023 09:55
@gdotdesign gdotdesign marked this pull request as ready for review August 8, 2023 12:28
@farism
Copy link
Contributor

farism commented Aug 25, 2023

A couple of localization thoughts just from experience with it in our prod app:

  1. There can potentially be hundreds/thousands of lines of text in a large application, multiplied by 10+ languages can easily add up to hundreds of kilobytes in your bundle. It would be nice from an optimization standpoint if each there was an option to have each locale code split out and loaded on demand. We do this in our app React apps by having translations live in separate .json files and using using dynamic import().
  2. When using a localization service (Phrase, Smartling, and other services like this) they generally expect to be working with some standardized data exchange format like .yaml or .json. Something to think about from a workflow perspective.
  3. Packages may need to ship with their own translations, and whatever system Mint goes with should have seamless integration between the package and the app. I think having the locale scope be open solves this issue? But not entirely sure if there are some other nuances.

Copy link
Member

@Sija Sija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach of making the translations a first class citizen. I believe though that the implementation should handle the pluralization, loading data from files and the other points raised by @farism.

@gdotdesign
Copy link
Member Author

I like the approach of making the translations a first class citizen. I believe though that the implementation should handle the pluralization, loading data from files and the other points raised by @farism.

I agree on all parts, but it needs to be a multi-stage process, we can't implement everything in one PR.

  1. I'm currently refactoring the compiler to allow dynamic imports, which will include locales.
  2. This is the hardest part to implement, since I presume everyone has its own format, so we either need to decide which format to use or we keep it as is and build the tooling around importing / exporting formats.
  3. The locale definitions are open, and if packages use namespaces it shouldn't be a big issue. The only thing we might need is to allow overriding a specific key but I wouldn't implement this until we run into the need in production.
  4. Pluralization and the whole translation logic is so wide (date-time, currencies, etc...) is that I fear that having them as language features are not really feasible.

Copy link
Contributor

@jansul jansul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would generally agree with @gdotdesign, there doesn't seem to be anything about this design that would prevent implementing most of the features mentioned.

The only awkward thing might be:

2. When using a localization service (Phrase, Smartling, and other services like this) they generally expect to be working with some standardized data exchange format like .yaml or .json. Something to think about from a workflow perspective.

However I don't think it's worth giving up the flexibility of the values being expressions to support these services. Hopefully we could find a nice way of importing/exporting locales in a way that works with them.

src/ast.cr Show resolved Hide resolved
core/source/Locale.mint Show resolved Hide resolved
documentation/Language/Locale.md Show resolved Hide resolved
Co-authored-by: jansul <jon@sul.ly>
@gdotdesign gdotdesign merged commit d04f5c0 into master Sep 17, 2023
3 checks passed
@gdotdesign gdotdesign deleted the locales branch September 17, 2023 19:10
@Sija Sija added the enhancement New feature or request label Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language Language feature
Development

Successfully merging this pull request may close these issues.

4 participants