The Apple docs for this (both in Xcode and webpage) have exactly no explanation of the parameters.
https://developer.apple.com/documentation/foundation/1418095-nslocalizedstring
For reference, the function signature is
NSLocalizedString(
_ key : String,
tableName: String? = default, // ??
bundle : Bundle = default,
value : String = default, // ????
comment : String
) -> String
I have a vague idea what the tableName
is -- but more information would be helpful. (Is it merely the filename for a strings file?) I have no idea what value
is for.
NSLocalizedString is a Foundation macro that returns a localized version of a string. It has two arguments: key , which uniquely identifies the string to be localized, and comment , a string that is used to provide sufficient context for accurate translation.
struct CustomLanguage { func createBundlePath () -> Bundle { let selectedLanguage = //recover the language chosen by the user (in my case, from UserDefaults) let path = Bundle. main. path(forResource: selectedLanguage, ofType: "lproj") return Bundle(path: path!) ! } }
The key used to look up an entry in a strings file or strings dictionary file. iOS 13.0+ iPadOS 13.0+ macOS 10.15+ Mac Catalyst 13.0+ tvOS 13.0+ watchOS 6.0+
The Objective-C documentation for NSLocalizedStringWithDefaultValue
explains the parameters:
Parameters
key
The key for a string in the specified table.tableName
The name of the table containing the key-value pairs. Also, the suffix for the strings file (a file with the .strings extension) to store the localized string.bundle
The bundle containing the strings file.value
The value to return if key is nil or if a localized string for key can’t be found in the table.comment
The comment to place above the key-value pair in the strings file.
Basically, the key
is looked up in a file named tableName.strings
in the specified bundle. That strings file will have the format:
# comment
"key" = "value"
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