-
Notifications
You must be signed in to change notification settings - Fork 23
Localization
Localization in general works as described in the Apple Documentation or this helpful tutorial. Strings files are included in the project and can be exported to and imported from Xliff files if necessary for translation by external translation agencies.
Strings files live in the Translations
directory,
To test localization, you can edit your currently active scheme, and in "Options", set the "Application Language". Don't commit this change please.
There is a Localizable.strings
file, but there are also files for individual subsystems of the app. Consider adding your strings to a fitting subsystem if possible.
If you put your strings in the Localizable.strings
file, you should add references to them into Strings.swift
. If you put them in another file, say MyOtherStringsFile.strings
, you should add references to them into Strings+MyOtherStringsFile.swift
.
Do not put NSLocalizedString
instances directly into your code please. Instead, add the to Strings.swift
or an extension thereof. Check if there is already a section there where your strings fit in well, and if not add one. Sections should look like below. Don't forget the tableName parameter.
Localized Strings should use keys that describe a path to where they can be found, like HomePanel.ContextMenu.OpenInNewTab
. Do not use "Open in New Tab" as a key!
public struct Strings {
// MARK: - Search
public struct Search {
public struct ThirdPartyEngines {
public static let AddSuccess = NSLocalizedString("Search.ThirdPartyEngines.AddSuccess", comment: "The success message that appears after a user sucessfully adds a new search engine")
public static let AddTitle = NSLocalizedString("Search.ThirdPartyEngines.AddTitle", comment: "The title that asks the user to Add the search provider")
// ...
}
// MARK: - Bookmarks
public struct Bookmarks {
public static let Title = NSLocalizedString("Bookmarks.Title" comment: "The label for the title of a bookmark")
}
}
Note that keys should be the same in both the strings file and in swift code. That means that if the key in the strings file is Search.ThirdPartyEngines.AddSuccess
, then I should be able to access it via Swift as Strings.Search.ThirdPartyEngines.AddSuccess
.