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.
quick-i18n is a simple and efficient internationalization (i18n) library for Python applications. It allows you to manage translations using JSON files, supports dynamic language switching, and provides formatting for translation strings.
Install the package via pip:
pip install quick-i18n
from quicki18n import i18n
# Initialize the i18n class
t = i18n(
languages=['en', 'es'],
default_language='en',
default_domain="default",
dev_mode=True # Set to False in production
)
# Set the current language
t.set_language('es')
# Get translations
print(t('Welcome to our application!')) # Translates based on the current language
# Use formatting in translations
print(t('Greeting, {name}', name='Alice', domain='messages'))
After execution quick-i18n generate for You json files:
{
"default": {
"welcome-to-our-application": "Welcome to our application!"
},
"messages": {
"greeting-name": "Greeting, {name}!"
}
}
When dev_mode is set to True, missing translation keys are automatically added to all language files, making it easier to manage translations during development.
When integrating the quick-i18n package into your Python project, it's important to organize your files and directories effectively to ensure maintainability and scalability. This guide provides recommendations for structuring your project to make the most out of quick-i18n.
A well-organized project structure enhances readability and maintainability. Here's a recommended structure when using quick-i18n:
your_project/
├── app/
│ ├── __init__.py
│ ├── i18n.py
│ ├── main.py
│ └── ... (other modules)
├── translations/
│ ├── en.json
│ ├── es.json
│ ├── ru.json
│ └── ... (other language files)
├── requirements.txt
├── README.md
└── ... (other files)
app/
: Contains your application code.translations/
: Stores your translation JSON files.requirements.txt
: Lists your project dependencies.README.md
: Provides information about your project.Place or generate your translation files in a dedicated translations/ directory at the root of your project. Each language has its own JSON file named after its language code (e.g., en.json for English).
Example en.json:
{
"default": {
"welcome": "Welcome to our application!",
"farewell": "Goodbye, {name}!"
},
"errors": {
"not_found": "The requested item was not found.",
"unauthorized": "You are not authorized to perform this action."
}
}
es.json
{
"default": {
"welcome": "¡Bienvenido a nuestra aplicación!",
"farewell": "¡Adiós, {name}!"
},
"errors": {
"not_found": "El elemento solicitado no fue encontrado.",
"unauthorized": "No estás autorizado para realizar esta acción."
}
}
Initialize quick-i18n in a central location within your application, such as the init.py file of your app/ package or a dedicated module (e.g., app/i18n.py).
# app/i18n.py
import os
from quicki18n import i18n
# Determine the path to the translations directory
translations_path = os.path.join(os.path.dirname(__file__), '..', 'translations')
# Initialize the i18n instance
t = i18n(
languages=['en', 'es', 'ru'],
default_language='en',
dev_mode=False, # Set to True during development
translations_path=translations_path
)
Import the translation instance t and use it to fetch translations within your application modules.
# app/main.py
from . import t
def greet_user(name):
welcome_message = t('default.welcome')
personalized_farewell = t('default.farewell', name=name)
print(welcome_message)
print(personalized_farewell)
if __name__ == "__main__":
t.set_language('es') # Set language to Spanish
greet_user('Carlos')
Output:
¡Bienvenido a nuestra aplicación!
¡Adiós, Carlos!
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please submit a pull request or open an issue for any improvements or bug fixes.
FAQs
A quick and easy internationalization library for Python.
We found that quick-i18n 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.