Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Lightweight i18n for Python.
pip install i18nx
from i18nx import I18n
i18n = I18n(
locale = 'en',
fallback = 'fr',
translations = {
'en': { 'message': { 'hello': 'Hello World!' } },
'fr': { 'message': { 'hello': 'Bonjour le monde !' } },
},
)
print(i18n.tr("message.hello")) # Hello World!
Interpolation
i18nx
use the Mustache like placeholders {}
syntax for interpolation.
from i18nx import I18n
i18n = I18n(
locale = 'en',
fallback = 'fr',
translations = {
'en': { 'message': { 'hello': 'Hello {name}!' } },
'fr': { 'message': { 'hello': 'Bonjour {name} !' } },
},
)
print(i18n.tr("message.hello", name = 'Mario')) # Hello Mario!
Pluralization
Use a pipe |
separator in combination with the param count
to define
plurals on the locale translations.
from i18nx import I18n
i18n = I18n(
locale = 'en',
fallback = 'fr',
translations = {
'en': {
'car': 'car | cars',
'apple': 'no apples | one apple | {count} apples',
},
},
)
print(i18n.tr("car")) # 'car'
print(i18n.tr("car", count = 0)) # 'car'
print(i18n.tr("car", count = 1)) # 'car'
print(i18n.tr("car", count = 2)) # 'cars'
print(i18n.tr("apple", count = 0)) # 'no apples'
print(i18n.tr("apple", count = 1)) # 'one apple'
print(i18n.tr("apple", count = 15)) # '15 apples'
List of Messages
from i18nx import I18n
i18n = I18n(
locale = 'en',
fallback_locale = 'fr',
translations = {
'en': {
"greetings": [
"Hey {firtname}!",
"Hi {firtname}!",
],
},
},
)
print(i18n.tr("greetings.0", firtname = 'Mario')) # 'Hey Mario!'
print(i18n.tr("greetings.1", firtname = 'Mario')) # 'Hi Mario!'
interface class I18n:
constructor(locale: str, fallback_locale: str, translations: Dict[str, Dict[str, Any]], show_warning = False)
# Active locale
@property locale: str
# Fallback locale
@property fallback_locale: str
# Available locales
@getter available_locales: List[str]
# Raw translations object for the active locale
@getter raw: dict
# Get translated text for the given dot path
@method tr(path: str, **params) -> str
# Get the raw message for the given dot path
@method get_raw_message(path: str) -> Union[str, None]
# Format the given raw message with the given params
@method format_raw_message(message: str, **params) -> str
At the top-level of your project run:
direnv allow
The next time your launch your terminal and enter the top-level of your
project, direnv
will check for changes.
Scripts
# run tests
make test
# run tests with coverage
make coverage
# run linter
make lint
# run build process
make dist
# publish
make publish
Under the MIT license. See LICENSE file for more details.
FAQs
Lightweight i18n for Python
We found that i18nx 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.