Skip to content

Showing options how to store localizable keys so that a string catalog can automatically detect them

Notifications You must be signed in to change notification settings

akoslowski/string-catalog-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Localization with String Catalogs

This project provides an iOS app with a string catalog for managing localizable strings. It is supposed to show options of how to store localizable keys so that a string catalog can automatically manage them.

Resources

Traits

ID Type SC compatible SwiftUI SwiftUI previews UIKit Key Access Parameters
a Swift.String.LocalizationValue ⚠️ ⚠️
b SwiftUI.LocalizedStringKey
c Foundation.LocalizedStringResource ⚠️
d SwiftUI.Text
f Foundation.NSLocalizedString
g Swift.String extension
h Swift.String(localized:)

Legend

Key Description
ID The variable name in the Examples
Type The type to store a localizable key
SC compatible Does the string catalog automatically find the specified keys in the project?
SwiftUI Do SwiftUI symbols come with an interface?
SwiftUI previews Do SwiftUI previews automatically reflect the current locale from environment?
UIKit Do UIKit symbols come with an interface?
Key Access Can the raw key be accessed, e.g. in tests?
Parameters Are parameters for choosing comment, table, bundle available?
  • ⚠️ Some types can and need to be converted into String before using them in UIKit, or SwiftUI
    • String(localized resource: LocalizedStringValue)
    • String(localized resource: LocalizedStringResource)

String Interpolation

All "SC compatible" types also support String interpolation to insert dynamic values into the localizable key.

For simplification these examples are not added to the project. The following code would result in a string catalog entry: Hello %@

func greeting(with name: String) -> LocalizedStringResource {
    LocalizedStringResource(
        "Hello \(name)",
        comment: "A short greeting with a name parameter"
    )
}

App vs. Preview

App SwiftUI preview

About

Showing options how to store localizable keys so that a string catalog can automatically detect them

Topics

Resources

Stars

Watchers

Forks

Languages