Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Pi18n is an internationalization library for Python
Install using pip
pip install pi18n
Pi18n lets you internationalize your Python app in a simple way. It works like this:
Provide Pi18n with as many JSON files as languages your app is going to support.
Each file will be named with the locale of the language it represents.
The content that is going to be placed in the app will be in each of these files, translated into the language that
the file represents and associated with a code.
is the translation associated to the code for every language.
Every JSON object of every file must have the same keys.
Translations can contain named parameters (placeholders) that will be replaced by a certain value on translation-time. Provide
as many as needed with this syntax: {param-code}
.
Instantiate an object of TranslationService
class. Its constructor must receive:
The path with the translation files.
The default locale.
Call the get
method of the TranslationService
instance for getting a translation:
Provide the translation code to the get
method as the first argument.
Optionally, provide parameters to the translation either as a dict or as keyword arguments.
resources/es.json
{
"HELLO_WORLD": "Hola mundo!",
"WITH_PARAMS": "Los parámetros son: {fruit1}, {fruit2} and {fruit3}"
}
resources/en.json
{
"HELLO_WORLD": "Hello world!",
"WITH_PARAMS": "Params are: {fruit1}, {fruit2} and {fruit3}"
}
TranslationService
main.py
from pi18n import TranslationService
translation_service = TranslationService('resources', 'es')
TranslationService
Get a translation:
translation = translation_service.get("HELLO_WORLD")
print(f"Message in Spanish: {translation}")
>>> "Message in Spanish: Hola mundo!"
Change locale at runtime:
translation_service.change_locale("en")
translation = translation_service.get("HELLO_WORLD")
print(f"Message in English: {translation}")
>>> "Message in English: Hello world!"
Get a translation that receives some params as a dict:
params = {"fruit1": "apple", "fruit2": "orange", "fruit3": "banana"}
translation = translation_service.get("WITH_PARAMS", params)
print(f"Message with params: {translation}")
>>> "Message with params: Params are: apple, orange and banana"
Get a translation that receives some params as kerword arguments:
translation = translation_service.get("WITH_PARAMS", fruit1="apple", fruit2="orange", fruit3="banana")
print(f"Message with params: {translation}")
>>> "Message with params: Params are: apple, orange and banana"
FAQs
A Python internationalization (i18n) package
We found that pi18n demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.