You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is probably not the xcstrings-tool fault, but I played around to verify how it would work for my setup, that's why I created an issue here, to hopefully find a way to fix the problem.
The issue is that when SPM package contains localized resources, either the new String Catalog or legacy *.strings, the localized string by using the default LocalizedStringResource won't be correctly resolved in the app.
After spending more time on the issue.
The problem is two-fold:
First of all there is no problem when you change the language in the system e.g. on the simulator to Germany. Then everything works as expected.
If you would like to test localization using App Language in the scheme configuration, then you need to also change the App Region respectively to the App Language. Only then LocalizedStringResource work as you would expect - which is QUITE surprising.
Update:
Oh, but there is another problem 🫣
When the preferred language is set from the iOS system app's settings:
then were are back to the same problem as with the scheme configuration only for the language.
It would mean that the best option is still to use
Text(String(localizable:...))
Especially, because of the inability to change the preferred language in the app without having to change the region - Locale.
nonameplum
changed the title
The default LocalizedStringResource does not work with SPM localized resources
The default LocalizedStringResource does not work with localized resources
Jan 6, 2025
nonameplum
changed the title
The default LocalizedStringResource does not work with localized resources
The defaulted LocalizedStringResource does not work with localized resources
Jan 6, 2025
Hey,
It is probably not the xcstrings-tool fault, but I played around to verify how it would work for my setup, that's why I created an issue here, to hopefully find a way to fix the problem.
The issue is that when SPM package contains localized resources, either the new String Catalog or legacy
*.strings
, the localized string by using the defaultLocalizedStringResource
won't be correctly resolved in the app.I made a simple app to demonstrate the problem: LocalizationSpm.zip
I made sure to set up
CFBundleAllowMixedLocalizations
(as suggested on swift forums) and inPackage.swift
definedefaultLocalization: "en"
.I created a bunch of
Text
usage checks that give this outcome when the app is running in the German language (by configuring the App Language scheme):This respective code in
TestView.swift
:The biggest issue is that none of those work:
even this one:
because internally all of those in the generated code will be resolved as
LocalizedStringResource
which seems to be not working in this case.Do I set up something wrong or is this a known issue of SPM localized resources with
LocalizedStringResource
?As you can see variants 2, 7, 8, 12, 16, 17, 19 works properly.
Most importantly this will work:
This could be used as a workaround at the moment if nothing better cannot be used.
Btw.
In SwiftUI Preview e.g.:
It will work as you would expect with the given examples.
The text was updated successfully, but these errors were encountered: