Comments (3)
Could you please share how you override language today when using LocalizedStringResource
? The API has improved a bit since NSLocalizedString
so you shouldn't need to do any bundle overrides anymore.
For example, in SwiftUI, you can just set the locale
in the environment to override:
struct MyView: View {
var body: some View {
VStack {
Text(.localizable.foo)
Text(.localizable.bar)
}
.environment(\.locale, Locale(identifier: "fr"))
}
}
For Foundation/UIKit, you can do something like this:
extension String {
init(french resource: LocalizedStringResource) {
var resource = resource
resource.locale = Locale(identifier: "fr")
self.init(localized: resource)
}
}
// String(french: .localizable.foo)
from xcstrings-tool.
Ah good point, yes, overriding environment works fine for SwiftUI view.
And for everything else it's good that we have an option to set locale on resource.
Probably this issue can be closed, but I would love to see this as example in README, thanks!
from xcstrings-tool.
Thanks for confirming! Great to hear that this can help 🚀 I'll keep the ticket open to track updating some docs.
from xcstrings-tool.
Related Issues (20)
- Add note to documentation about unwanted target dependencies
- Integrating XCStrings Tool into a Swift Package Target has wrong package git url HOT 2
- ExtractionState config HOT 3
- Feature Suggestion: Support to other build systems HOT 1
- Default values with UnsafeRawPointers do not compile HOT 4
- Ensure that snapshots compile
- Multiple commands produce generated source when working with embedded watchOS app HOT 5
- Generate.swift in the Release files look different HOT 3
- Support SwiftSyntax 5.10
- Improve SwiftUI support on iOS 15 HOT 16
- String containing a single `%` is parsed incorrectly HOT 1
- Duplicates in Localizable.xcstrings in 0.2.0 HOT 9
- Set default value to be fallback documenting comment HOT 2
- Suggestion/Question init LocalizedStringKey with .localizable.key HOT 8
- How to use with Github Actions? HOT 3
- Duplicate accessors generated in extensions on both `String` and `LocalizedStringResource`
- Support deferred formatting
- Generated @available has trailing whitespace HOT 5
- Build errors after updating from 0.4.1 to higher version HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xcstrings-tool.