TextConstantApi
The text_constant module lets you fetch and format text constants
Functions
Function | Parameters | Return Value | Description |
|---|---|---|---|
cache_clear | Clears the text constant cache | ||
get_formatted_text_constant | _id: CONST | The text constant with the optional arguments formatted into the text | Fetches the text constant and replace placeholders. When no argument was given for a placeholder it is simply ignored. Text constants are only fetched once and then cached. |
get_text_constant | _id: CONST | The text constant | Fetches a text constant. When default is |
safe_format | text: A string with format parameters like | The text with placeholders replaced | Safely formats a string without raising an error when not all placeholders were replaced |
Examples
Using safe_format
from ppms.text_constant import safe_format
text = "The quick brown {jumpee} jumped over the lazy {animal}"
# If you used text.format() then it would raise a KeyError
formatted_text = safe_format(text, jumpee='fox')
# formatted_text is now "The quick brown fox jumped over the lazy {animal}"