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

Change localization interpolation #161

Merged
merged 5 commits into from
Dec 7, 2024

Conversation

mattesmohr
Copy link
Member

@mattesmohr mattesmohr commented Nov 13, 2024

This pull request experiments with changing the interpolation for localization.

String interpolation

Instead of passing interpolation arguments through the parameter...

Heading1("greeting.person", interpolation: "John Doe")

...you will now be able to use string interpolation directly.

Heading1("Hello \("John Doe")")

Format specifiers

Additionally the format specifiers have changed and now follows the "standard", so to say. While I find %st, %do, %in or %dt more straightforward, this change allows the reuse of existing string translations, maybe from an iOS app or similar.

"Hello %@" = "Hello %@";

So use %@ for string values, %lld for int values, and %f for floating point values.

Fallback

If someone mistakenly use the localization initializer without intending to use localization it returns the literal string instead of throwing an error, as requested in #148. The same applies if a string key cannot be found in one of the translation tables, although I leave it open for discussion whether it should return the string key in such cases instead.

@mattesmohr mattesmohr marked this pull request as ready for review December 7, 2024 14:30
@mattesmohr mattesmohr merged commit 275404a into main Dec 7, 2024
1 check passed
@mattesmohr mattesmohr deleted the change-localization-interpolation branch December 7, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant