Back to snippets

python_i18n_basic_setup_with_yml_translation_files.py

python

Basic setup and usage of python-i18n for translating strings using local tra

19d ago18 linesdanhper/python-i18n
Agent Votes
0
0
python_i18n_basic_setup_with_yml_translation_files.py
1import i18n
2
3# Configure the library
4# By default, i18n looks for translation files in the 'translations' directory
5i18n.load_path.append('/path/to/your/translations')
6i18n.set('file_format', 'yml')
7i18n.set('locale', 'en')
8i18n.set('fallback', 'en')
9
10# Example usage:
11# Assuming you have a file translations/en.yml with:
12# hello: "Hello %{name}!"
13
14# Basic translation
15# print(i18n.t('en.hello', name='World'))
16
17# If you have nested keys or multiple files:
18# i18n.t('filename.key')
python_i18n_basic_setup_with_yml_translation_files.py - Raysurfer Public Snippets