language: Sprachcode kwargs: Arguments to replace the placeholders in the text constant
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.
language: Sprachcode default: A string to return when no text constant with the given id exists
The text constant
Fetches 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 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}"
PY
Datenschutzhinweis
Wir verwenden Cookies und andere Technologien auf unserer Website. Mehr Informationen finden Sie hier: Datenschutzerklärung