<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Bundle/localizedString(forKey:value:table:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBundle(im)localizedStringForKey:value:table:"
  },
  "title" : "localizedString(forKey:value:table:)"
}
-->

# localizedString(forKey:value:table:)

Returns a localized version of the string designated by the specified key and residing in the specified table.

```
func localizedString(forKey key: String, value: String?, table tableName: String?) -> String
```

## Parameters

`key`

The key for a string in the table identified by `tableName`.

`value`

The value to return if `key` is `nil` or if a localized string for `key` can’t be found in the table.

`tableName`

The receiver’s string table to search. If `tableName` is `nil` or is an empty string, the method attempts to use the table in `Localizable.strings`.

## Return Value

A localized version of the string designated by `key` in table `tableName`. This method returns the following when key is `nil` or not found in table:

- If `key` is `nil` and `value` is `nil`, returns an empty string.
- If `key` is `nil` and `value` is non-`nil`, returns value.
- If `key` is not found and `value` is `nil` or an empty string, returns `key`.
- If `key` is not found and `value` is non-`nil` and not empty, return `value`.

## Discussion

For more details about string localization and the specification of a `.strings` file, see “[String Resources](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html#//apple_ref/doc/uid/10000051i-CH6).”

Using the user default `NSShowNonLocalizedStrings`, you can alter the behavior of [`localizedString(forKey:value:table:)`](/documentation/Foundation/Bundle/localizedString(forKey:value:table:)) to log a message when the method can’t find a localized string. If you set this default to <doc://com.apple.documentation/documentation/Swift/true> (in the global domain or in the application’s domain), then when the method can’t find a localized string in the table, it logs a message to the console and capitalizes `key` before returning it.

The following example cycles through a static array of keys when a button is clicked, gets the value for each key from a strings table named `Buttons.strings`, and sets the button title with the returned value:

```objc
- (void)changeTitle:(id)sender
{
    static int keyIndex = 0;
    NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
 
    NSString *locString = [thisBundle
        localizedStringForKey:assortedKeys[keyIndex++]
        value:@"No translation" table:@"Buttons"];
    [sender setTitle:locString];
    if (keyIndex == MAXSTRINGS) keyIndex=0;
}
```

## See Also

[`path(forResource:ofType:inDirectory:)`](/documentation/Foundation/Bundle/path(forResource:ofType:inDirectory:)-swift.type.method)

Returns the full pathname for the resource file identified by the specified name and extension and residing in a given bundle directory.

[`paths(forResourcesOfType:inDirectory:)`](/documentation/Foundation/Bundle/paths(forResourcesOfType:inDirectory:)-swift.type.method)

Returns an array containing the pathnames for all bundle resources having the specified extension and residing in the bundle directory at the specified path.

[`paths(forResourcesOfType:inDirectory:)`](/documentation/Foundation/Bundle/paths(forResourcesOfType:inDirectory:)-swift.method)

Returns an array containing the pathnames for all bundle resources having the specified filename extension and residing in the resource subdirectory.

[`path(forResource:ofType:inDirectory:)`](/documentation/Foundation/Bundle/path(forResource:ofType:inDirectory:)-swift.method)

Returns the full pathname for the resource identified by the specified name and file extension and located in the specified bundle subdirectory.

[`path(forResource:ofType:)`](/documentation/Foundation/Bundle/path(forResource:ofType:))

Returns the full pathname for the resource identified by the specified name and file extension.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)