Skip to content

Latest commit

 

History

History
89 lines (73 loc) · 8.29 KB

cp.strings.md

File metadata and controls

89 lines (73 loc) · 8.29 KB

docs » cp.strings


Provides strings from (potentially) multiple sources, with support for loading from multiple languages.

local strs = require("cp.strings").new():fromPlist("/Path/To/Resources/${language}.lproj/MYLocalization.strings")
local value = strs:find("en", "AKey")

This will load the file for the specified language (replacing ${language} with "en" in the path) and return the value. Note: This will load the file on each request. To have values cached, use the cp.strings module and specify a plist as a source.

Submodules

API Overview

API Documentation

Constructors

Signature cp.strings.new() -> cp.strings
Type Constructor
Description Creates a new strings instance. You should add sources with the from or fromPlist methods.
Parameters
  • None
Returns
  • The new cp.strings

Methods

| Signature | cp.strings:find(language, key) -> string | nil | | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Searches for the specified key in the specified language, caching the result when found. | | Parameters |

  • language - The language code to look for (e.g. "en", or "fr").
  • key - The key to retrieve from the file.
| | Returns |
  • The value of the key, or nil if not found.
|

| Signature | cp.strings:findInSources(language, key) -> string | nil | | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Searches directly in the sources for the specified language/key combination. | | Parameters |

  • language - The language code to look for (e.g. "en", or "fr").
  • key - The key to retrieve from the file.
| | Returns |
  • The value of the key, or nil if not found.
|

| Signature | cp.strings:findKeysIn(language, value) -> string | nil | | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Searches for the list of keys with a matching value, in the specified language. | | Parameters |

  • language - The language code to look for (e.g. "en", or "fr").
  • value - The value to search for.
| | Returns |
  • The array of keys, or {} if not found.
|

| Signature | cp.strings:findKeysInSources(language, value) -> string | nil | | -----------------------------------------------------|---------------------------------------------------------------------------------------------------------| | Type | Method | | Description | Searches directly in the sources for the specified language/value combination. | | Parameters |

  • language - The language code to look for (e.g. "en", or "fr").
  • value - The value to search for.
| | Returns |
  • The array of keys, or {} if not found.
|

Signature cp.strings:from(source) -> cp.strings
Type Method
Description Adds the source to the strings sources.
Parameters
  • source - The source to add.
Returns
  • The current cp.strings instance.
Signature cp.strings:fromPlist(pathPattern) -> cp.strings
Type Method
Description Convenience method for addedn a plist source to the strings instance.
Parameters
  • pathPattern - The path to load from. May contain a special ${language} marker which will be replace with the provided langauge when searching.
Returns
  • The current cp.strings instance.