String Catalog Localization with Tuist

Question or problem

Does Tuist support localization via String Catalog (`.xcstrings`)?

Context

  • Tuist version: 4.115.1

I have a modular architecture with feature targets as static frameworks. Each feature has:

  • Sources: `Features/MyFeature/Sources/**`
  • Resources: `Features/MyFeature/Resources/**` (contains `Localizable.xcstrings`)
  • Build setting: `STRING_CATALOG_GENERATE_SYMBOLS = YES`

The `Localizable.xcstrings` file is properly included in the target’s resources and appears in the generated Xcode project.

Issues

  1. Automatic string extraction doesn’t work during build.
  2. Localisation doen’t work. Ex: `Text(“Test”, bundle: MyFeatureResources.bundle)`

Is there any tutorial or documentation how to setup localisation in project?

Hey,

Tuist generates its own string accessors for static frameworks – right now, it’s not possible to use the Xcode catalog for static frameworks with Tuist. We’ll need to bring this PR which initially introduced some regressions.

1 Like

Thank you. Then I’ll go with legacy Localizable.strings files.

Another question with Resource accessors in static frameworks. A couple of years ago, to be able to use localization in my feature (static framework). I had to modify the template: Strings.stencil

Instead of

extension CategoryFeatureStrings {
  private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
    let format = Bundle.module.localizedString(forKey: key, value: nil, table: table)
    return String(format: format, locale: Locale.current, arguments: args)
  }
} 

use custom modified template generates:

extension CategoryFeatureStrings {
  private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
    let lang = Locale.preferredLanguages.first! \\ eg. fr
    let path = Bundle.module.path(forResource: lang, ofType: "lproj")
    let format = Bundle(path: path).localizedString(forKey: key, value: nil, table: table)
    return String(format: format, locale: Locale.current, arguments: args)
  }
} 
  1. Link to https://github.com/tuist/tuist/tree/main/Sources/TuistGenerator/Templates from doc Synthesized files · Projects · Features · Guides · Tuist shows 404
  2. Is this way of localisation valid?