-
-
Notifications
You must be signed in to change notification settings - Fork 106
String Translation
As Anjani supports multi-language, localized string placed on language/
with a .yml
file.
~Plugin.text()
:
Parse the string with the user language setting. Return English string in case other language doesn't have the string requested.
Parameters:
-
chat_id (
int
) - Id of the sender if in PM's or chat_id to fetch the user language setting. -
name (
str
) - String name(key) to parse. -
*args (
any
, Optional) - One or more values that should be formatted and inserted in the string. The value should be in order based on the language string placeholder. -
noformat (
bool
, Optional) - If exist and True, the text returned will not be formatted (if you don't want to insert any value to the placeholders). Default to False. -
**kwargs (
any
, Optional) - One or more keyword values that should be formatted and inserted in the string. Based on the keyword placeholder on the language strings.
Bellow is the string on the en.yaml
file.
test-string : Good {} my name is {my_name}.
To parse the string, simply call the text method via Plugin instance ~Plugin.text()
.
from anjani import command, plugin
class ExampleText(plugin.Plugin):
name = "Example Text"
async def cmd_test(self, ctx: command.Context) -> str:
return await self.text(
ctx.chat.id, "test-string", "morning", my_name="Anjani"
)
# The Message text will be "Good morning my name is Anjani."
Wiki of Anjani © Copyright 2021, UserBotIndo