In my previous framework, I have a localizable.strings file with some global entries for localization. On the left lane, there was a “Localize” button in Xcode to do this.
How can I do this with Swift Package Manager?
Click on iOS->App/Single View App->Next. Name your project and select the language as Swift. Select a desired location and click on Create. To start with Localization, click on your Project Name -> go to Info Tab -> Under Localizations, click on the '+' button.
Use it in custom SwiftUI views to make them ready for localization. Enable the "Use Compiler to Extract Swift Strings" build setting to extract LocalizedStringKeys from code when exporting for localization in Xcode. Format your strings to internationalize your code, and style them with Markdown.
Step 1: Create Localizable.Select File → New → File… or just tap Ctrl+N or Cmd+N . Search for strings and you will see Strings File in Resource window: Choose Strings File and name the file Localizable : Now, let's select Localizable.
To add localizable string file in SPM, it is possible from swift-tools-version: 5.3
,
Changes in Package.swift
,
Needs to set defaultLocalization: "en"
then add resources filed in target like,
And package structure should be like,
And to access localizable string through code in the package,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With