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

Support custom Locale when using iOS 15 compatible String initialiser #52

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

liamnichols
Copy link
Owner

Unlike LocalizedStringResource, the properties within the generated String.Localizable type remain private to the generated source and cannot be directly accessed.

This causes an issue if you need to be able to change the Locale value to something other than .current.

To address this, I've updated String.init(localizable:) to be String.init(localizable:locale:), with a nullable value.

If the custom locale is nil (the default value), we will use the original locale that is supplied by code generation.

If a value is set, it will take priority and allows you to override the language returned, for example:

String(localizable: .greeting) // Hello
String(localizable: .greeting, locale: Locale(identifier: "fr")) // Bonjour

@liamnichols liamnichols self-assigned this Apr 12, 2024
@liamnichols liamnichols marked this pull request as ready for review April 12, 2024 16:18
@liamnichols liamnichols merged commit 839f2e4 into main Apr 12, 2024
3 checks passed
@liamnichols liamnichols deleted the ln/string-locale-override branch April 12, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant