Skip to content

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