Die Dokumentation ab Version 39.5.17 von PLANTA project finden Sie in der neuen PLANTA Online-Hilfe.

text_constant

The text_constant module lets you fetch and format text constants

Functions

FunctionSorted ascending Parameters Return Value Description
cache_clear()     Clears the text constant cache
get_formatted_text_constant(_id, language=None, **kwargs) _id: CONST

language: Sprachcode
kwargs: Arguments to replace the placeholders in the text constant
The text constant with the optional arguments formatted into the text Fetch 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, language=None, default=None) _id: CONST

language: Sprachcode
default: A string to return when no text constant with the given id exists
The text constant Fetch a text constant. When default is None and no constant exists with that id, a ValueError is raised. Text constants are only fetched once and then cached.
safe_format(text, **formatting_parameters) text: A string with format parameters like 'Hello {user}'
formatting_parameters: Arguments to replace the placeholders in the text
The text with placeholders replaced Safely format 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}"

         PLANTA project









 
  • Suche in Topic-Namen

  • Suche in Topic-Inhalten
This site is powered by the TWiki collaboration platform Powered by Perl