Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add localizable.strings to Swift Package?

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?

like image 601
TruMan1 Avatar asked Aug 26 '19 11:08

TruMan1


People also ask

How do you implement localization in iOS Swift?

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.

How do I use localized strings in SwiftUI?

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.

How do I add localizable strings?

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.


Video Answer


1 Answers

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,

enter image description here

And package structure should be like,

enter image description here

And to access localizable string through code in the package,

enter image description here

like image 152
chirag Avatar answered Oct 10 '22 05:10

chirag