### Install Project with Dependencies Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Installs the project and its development dependencies using flit. Ensures symlinking for development. ```bash python3 -m pip install -U flit flit install --deps=develop --symlink ``` -------------------------------- ### Create Main Entry Point Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Sets up the main entry point for the l10n_playground package to run the example functionality. ```python from .example import main main() ``` -------------------------------- ### Install l10n with CLI support Source: https://github.com/orsinium-labs/l10n/blob/master/docs/quickstart.md Install the l10n library with the necessary components for command-line interface usage. ```bash python3 -m pip install 'l10n[cli]' ``` -------------------------------- ### Translated PO File Example Source: https://context7.com/orsinium-labs/l10n/llms.txt Example of a PO file after using 'l10n translate', showing fuzzy translations. ```po #: ./myapp/example.py:9 #, fuzzy msgid "Hello, world!" msgstr "Привет, мир!" #: ./myapp/example.py:15 #, fuzzy, python-brace-format msgid "Hello, {user_name}!" msgstr "Привет, {user_name}!" ``` -------------------------------- ### Complete Application Example: Localization Integration Source: https://context7.com/orsinium-labs/l10n/llms.txt Demonstrates integrating l10n for greeting messages, price display, and notification counts in a Python application. Shows handling different languages and pluralization. ```python # myapp/translations.py from l10n import Locales locales = Locales() def say_hello(name: str, lang: str = 'en') -> None: loc = locales[lang] msg = loc.get('Hello, {user_name}!').format(user_name=name) print(msg) def show_price(amount: float, lang: str = 'en') -> None: loc = locales[lang] label = loc.get('Total price:') formatted = loc.format_currency(amount, grouping=True) print(f"{label} {formatted}") def show_notifications(count: int, lang: str = 'en') -> None: loc = locales[lang] msg = loc.get( 'You have {n} new notification', plural='You have {n} new notifications', n=count ).format(n=count) print(msg) # Usage if __name__ == '__main__': say_hello('Alice', lang='en') # Hello, Alice! say_hello('Alice', lang='ru') # Привет, Alice! show_price(1234.56, lang='de') # Gesamtpreis: 1.234,56 € show_notifications(1, lang='en') # You have 1 new notification show_notifications(5, lang='en') # You have 5 new notifications show_notifications(21, lang='ru') # У вас 21 новое уведомление ``` -------------------------------- ### Generated PO File Example Source: https://context7.com/orsinium-labs/l10n/llms.txt Example of a PO file generated by the 'l10n extract' command, including header and translatable strings. ```po # Header with metadata msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" #: ./myapp/example.py:9 msgid "Hello, world!" msgstr "" #: ./myapp/example.py:15 msgid "Hello, {user_name}!" msgstr "" ``` -------------------------------- ### Format Month and Day of Week Source: https://context7.com/orsinium-labs/l10n/llms.txt Format month names and days of the week, with options for abbreviation and adjusting the start of the week. Requires the locale to be installed in the OS. ```python # Format month name loc_ru = locales['ru'] print(loc_ru.format_month(3)) # "Март" print(loc_ru.format_month(3, abbreviate=True)) # "Мар" # Format day of week (0 = Sunday by default) print(loc_ru.format_dow(1)) # "Понедельник" print(loc_ru.format_dow(1, abbreviate=True)) # "Пн" print(loc_ru.format_dow(1, sunday=1)) # Adjust if Sunday=1 in your system ``` -------------------------------- ### Python code for string internationalization Source: https://github.com/orsinium-labs/l10n/blob/master/docs/quickstart.md Demonstrates how to use the l10n library in Python to get localized strings. Ensure the Locales object is initialized. ```python from l10n import Locales locales = Locales() def say_hello(lang='en'): loc = locales[lang] msg = loc.get('Hello, world!') print(msg) ``` -------------------------------- ### Format Dates, Times, and Datetimes Source: https://context7.com/orsinium-labs/l10n/llms.txt Format date, time, and datetime objects according to locale conventions. Requires the locale to be installed in the OS. ```python from datetime import date, time, datetime from l10n import Locales locales = Locales() # Format date loc_de = locales['de'] today = date(2024, 3, 15) print(loc_de.format_date(today)) # "15.03.2024" # Format time now = time(14, 30, 0) print(loc_de.format_time(now)) # "14:30:00" # Format datetime dt = datetime(2024, 3, 15, 14, 30, 0) print(loc_de.format_datetime(dt)) # "15.03.2024 14:30:00" ``` -------------------------------- ### Manually Edit en.po File Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Edit the `.po` file directly in a text editor to provide translations. This example shows the initial state of the English `.po` file. ```elixir #: ./l10n_playground/example.py:9 msgid "Hello, world!" msgstr "Hello, world!" ``` -------------------------------- ### Call translated function Source: https://github.com/orsinium-labs/l10n/blob/master/docs/quickstart.md Example of calling the internationalized function with a specific language code to see the translated output. The translation is automatically loaded after compilation. ```python from example import say_hello say_hello(lang='uk') # Привіт Світ! ``` -------------------------------- ### Create Project Directory Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Initializes a new project directory for l10n development. ```bash mkdir l10n-playground cd l10n-playground ``` -------------------------------- ### Initialize Project Version Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Sets the initial version for the l10n_playground package. ```python """Experimenting with l10n""" __version__ = "1.0.0" ``` -------------------------------- ### Initialize Locales Catalog Source: https://context7.com/orsinium-labs/l10n/llms.txt Create a Locales catalog, which automatically discovers project structure. Access specific locales by language code or use .get() for fallback. ```python from l10n import Locales # Create locales catalog (auto-discovers project structure) locales = Locales() # Access locale by language code locale_en = locales['en'] locale_ru = locales['ru'] # Get locale with None fallback if not found locale = locales.get('fr') # Returns None if French not available # Get cached locale (caches up to 16 recently used) locale_cached = locales.get_cached('de') # List all available languages print(locales.languages) # frozenset({'en', 'ru', 'uk'}) # Get all locale objects all_locales = locales.locales # tuple of Locale objects # Detect system language from environment system_lang = locales.system_language # e.g., 'en_US' system_locale = locales.system_locale # Locale object or None # Custom path and format locales_custom = Locales( path='/path/to/locales', format='{language}.mo' ) ``` -------------------------------- ### Run Application with Default Language Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Execute your application using the default language settings. This command assumes the application is run from the project root. ```bash $ python3 -m l10n_playground Hello, world! ``` -------------------------------- ### Run Application with Specific Language Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Run your application and specify a language using the `--lang` flag. This allows users to select their preferred language at runtime. ```bash $ python3 -m l10n_playground --lang=ru Привет, мир! ``` -------------------------------- ### Configure pyproject.toml for l10n Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Sets up project metadata and dependencies, including l10n, using pyproject.toml. Requires flit for dependency management. ```toml [build-system] requires = ["flit_core >=3.2,<4"] build-backend = "flit_core.buildapi" [project] name = "l10n_playground" dynamic = ["version", "description"] requires-python = ">=3.7" dependencies = ["l10n"] [project.optional-dependencies] dev = ["l10n[cli]"] ``` -------------------------------- ### Compile Messages to .mo Files Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Compile human-readable `.po` files into binary `.mo` files, which are optimized for machine use at runtime. This command generates `.mo` files in the specified locale directory. ```bash python3 -m l10n compile ``` -------------------------------- ### Update All Existing .po Files Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Run `l10n extract` without any language arguments to update all existing `.po` files with any new or changed messages found in your code. ```bash l10n extract ``` -------------------------------- ### Define l10n Locales and Say Hello Function Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Initializes the Locales class and defines a function to retrieve and print localized messages. Assumes 'en' locale is available. ```python from argparse import ArgumentParser from l10n import Locales locales = Locales() def say_hello(lang: str = 'en') -> None: loc = locales[lang] msg = loc.get('Hello, world!') print(msg) def main() -> None: parser = ArgumentParser() parser.add_argument('--lang', default='en') args = parser.parse_args() say_hello(lang=args.lang) ``` -------------------------------- ### CLI: Compile Messages to MO Format Source: https://context7.com/orsinium-labs/l10n/llms.txt Use the 'compile' command to convert PO text files into binary MO files for runtime localization. Optionally exclude fuzzy translations. ```bash # Compile all PO files to MO format python3 -m l10n compile # Exclude fuzzy (unreviewed) translations python3 -m l10n compile --no-fuzzy ``` -------------------------------- ### Translate Country, Currency, and Language Names Source: https://context7.com/orsinium-labs/l10n/llms.txt Translate standard ISO country, currency, and language names into the target locale. Requires the 'iso-codes' package. ```python from l10n import Locales locales = Locales() loc = locales['ru'] # Translate country names (ISO 3166-1) print(loc.translate_country('Germany')) # "Германия" print(loc.translate_country('United States')) # "Соединённые Штаты" print(loc.translate_country('Japan')) # "Япония" # Translate currency names (ISO 4217) print(loc.translate_currency('Euro')) # "Евро" print(loc.translate_currency('United States Dollar')) # "Доллар США" # Translate language names (ISO 639-2/3) print(loc.translate_language('German')) # "Немецкий" print(loc.translate_language('English')) # "Английский" print(loc.translate_language('French')) # "Французский" ``` -------------------------------- ### CLI: Translate Messages with Google Translate Source: https://context7.com/orsinium-labs/l10n/llms.txt Use the 'translate' command to automatically translate PO files using the Google Translate API. Translations are marked as 'fuzzy' for manual review. ```bash # Translate all PO files python3 -m l10n translate # Translations are marked as "fuzzy" for manual review ``` -------------------------------- ### View Translated ru.po File Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md After running the translation command, the `.po` file will be updated with translated strings. The `fuzzy` flag indicates that the translation was machine-generated and may require review. ```elixir #: ./l10n_playground/example.py:9 #, fuzzy msgid "Hello, world!" msgstr "Привет, мир!" ``` -------------------------------- ### Compile translations Source: https://github.com/orsinium-labs/l10n/blob/master/docs/quickstart.md Compile all translation files into a binary format for efficient loading by the l10n library at runtime. This step is necessary after extracting or modifying translations. ```bash python3 -m l10n compile ``` -------------------------------- ### Extract Messages for Localization Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Generates PO translation files for specified languages (English and Russian) from the project's code. ```bash python3 -m l10n extract --lang=en python3 -m l10n extract --lang=ru ``` -------------------------------- ### Format Integers and Floats Source: https://context7.com/orsinium-labs/l10n/llms.txt Format integers with thousands separators and floats with locale-specific decimal separators. Supports grouping and precision control. ```python from decimal import Decimal from l10n import Locales locales = Locales() loc = locales['de'] # Format integers with thousands separator print(loc.format_int(1234567)) # "1.234.567" # Format floats with locale decimal separator print(loc.format_float(1234.56)) # "1234,56" print(loc.format_float(1234.56, grouping=True)) # "1.234,56" print(loc.format_float(1234.5678, precision=2)) # "1234,57" ``` -------------------------------- ### Translate Messages with Google Translate Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Use the `l10n translate` command to automatically translate all messages in your `.po` files using Google Translate's unofficial API. This is useful when a human translator is not available. ```bash python3 -m l10n translate ``` -------------------------------- ### Translate extracted strings Source: https://github.com/orsinium-labs/l10n/blob/master/docs/quickstart.md Initiate the translation process for extracted strings. This command typically uses configured translation services. ```bash python3 -m l10n translate ``` -------------------------------- ### Access Locale Properties Source: https://context7.com/orsinium-labs/l10n/llms.txt Access locale-specific properties such as decimal separators, thousands separators, and currency symbols. ```python # Access locale properties print(loc.decimal_dot) # "," print(loc.thousands_separator) # "." print(loc.currency_symbol) # "€" ``` -------------------------------- ### l10n.Locales Class Source: https://github.com/orsinium-labs/l10n/blob/master/docs/api.md Manages a collection of compiled (.mo) locale files. ```APIDOC ## Class l10n.Locales ### Description Class allowing you to work with compiled (.mo) files collection. ### Parameters #### Path Parameters - **path** (Path | None) - Optional - where compiled locales are located. - **format** (str) - Optional - file name template for compiled locales. Default: '{language}.mo' ### Methods #### get(language: str) -> Locale | None Find locale for the given language. #### get_cached(language: str) -> Locale | None The same as get but caches the returned Locale. ### Properties #### languages : frozenset[str] List all languages for which a locale is available in the catalog. #### locales : tuple[Locale, ...] List all locales available in the catalog. #### system_locale : Locale | None The Locale for the default system language. #### system_language : str | None The current system language detected from env vars. ``` -------------------------------- ### CLI: Extract Messages Source: https://context7.com/orsinium-labs/l10n/llms.txt Use the 'extract' command to scan Python source code and generate PO files for translation. Specify languages or update all existing files. ```bash # Extract messages for a specific language (creates locales/uk.po) python3 -m l10n extract --lang=uk # Extract for multiple languages python3 -m l10n extract --lang=en python3 -m l10n extract --lang=ru python3 -m l10n extract --lang=de # Update all existing PO files with new messages python3 -m l10n extract ``` -------------------------------- ### Translate Messages with Locale.get Source: https://context7.com/orsinium-labs/l10n/llms.txt Retrieve translations using the .get() method. It supports format placeholders, context for disambiguation, translator comments, and plural forms. ```python from l10n import Locales locales = Locales() loc = locales['ru'] # Basic translation msg = loc.get('Hello, world!') print(msg) # "Привет, мир!" # Translation with format placeholders msg = loc.get('Hello, {user_name}!').format(user_name='Alice') print(msg) # "Привет, Alice!" # Translation with context (disambiguation) msg_menu = loc.get('Open', context='menu') # "Открыть" (menu action) msg_status = loc.get('Open', context='status') # "Открыто" (status indicator) # Translation with comment for translators msg = loc.get( 'Click here to continue', comment='Button label on checkout page' ) # Plural forms handling n_msgs = 5 msg = loc.get( '{n} message', plural='{n} messages', n=n_msgs ).format(n=n_msgs) print(msg) # "5 сообщений" (Russian plural form) # Another plural example def show_items(count: int, lang: str = 'en') -> str: loc = locales[lang] return loc.get( '{n} item in cart', plural='{n} items in cart', n=count ).format(n=count) print(show_items(1, 'en')) # "1 item in cart" print(show_items(3, 'en')) # "3 items in cart" print(show_items(21, 'ru')) # "21 товар в корзине" ``` -------------------------------- ### Format Decimals and Currency Source: https://context7.com/orsinium-labs/l10n/llms.txt Format Decimal objects and currency values according to locale conventions, including grouping and international currency codes. Supports negative values. ```python # Format decimals val = Decimal('9999.99') print(loc.format_decimal(val, grouping=True)) # "9.999,99" # Format currency print(loc.format_currency(1234.56)) # "1234,56 €" print(loc.format_currency(1234.56, grouping=True)) # "1.234,56 €" print(loc.format_currency(1234.56, international=True)) # "1234,56 EUR" print(loc.format_currency(-50.00)) # "-50,00 €" ``` -------------------------------- ### Extract Messages for New Language Source: https://github.com/orsinium-labs/l10n/blob/master/docs/intro.md Use the `l10n extract --lang=nl` command to generate a `.po` file for a new language, such as Dutch (`nl`). This command scans your code for translatable strings. ```bash l10n extract --lang=nl ``` -------------------------------- ### Format Strings with Python Brace Format Source: https://github.com/orsinium-labs/l10n/blob/master/docs/advanced.md Use `str.format` for string formatting to ensure placeholders are not translated. This method is compatible with `python-brace-format` and prevents `l10n translate` from altering placeholders. ```python loc = locales[lang] msg = loc.get('Hello, {user_name}!').format(user_name=user.name) ``` -------------------------------- ### Extract Static Strings for Translation Source: https://context7.com/orsinium-labs/l10n/llms.txt Use TYPE_CHECKING to include strings for translation that are not evaluated at runtime. This ensures that these strings are available for extraction by l10n tools without affecting the application's runtime behavior. ```python from typing import TYPE_CHECKING # These strings are extracted but never executed if TYPE_CHECKING: from l10n import Locales loc = Locales()['en'] loc.get('Welcome message') loc.get('Error: connection failed') loc.get('Success!') ``` -------------------------------- ### Number Formatting Functions Source: https://github.com/orsinium-labs/l10n/blob/master/docs/api.md Functions to format numbers with locale-aware separators and precision. ```APIDOC ## format_float(n: int | float | Decimal, grouping: bool = False, monetary: bool = False, precision: int | None = None, strip_zeros: bool | None = None, exp: bool = False) -> str ### Description Format float or Decimal with the correct decimal dot. ### Parameters * **grouping** (bool) - Optional - add thousands separator. * **monetary** (bool) - Optional - use monetary thousands separator which may be different from a regular one for some locales. * **precision** (int | None) - Optional - if specified, include exactly so many digits in the decimal part. * **strip_zeros** (bool | None) - Optional - whatever to remove trailing zeros from the end. If not specified, will be set to True only if precision is not specified. * **exp** (bool) - Optional - if True, represent large numbers in scientific exponent notation. ## format_decimal(n: int | float | Decimal, grouping: bool = False, monetary: bool = False, precision: int | None = None, strip_zeros: bool | None = None, exp: bool = False) -> str ### Description Format float or Decimal with the correct decimal dot. ### Parameters * **grouping** (bool) - Optional - add thousands separator. * **monetary** (bool) - Optional - use monetary thousands separator which may be different from a regular one for some locales. * **precision** (int | None) - Optional - if specified, include exactly so many digits in the decimal part. * **strip_zeros** (bool | None) - Optional - whatever to remove trailing zeros from the end. If not specified, will be set to True only if precision is not specified. * **exp** (bool) - Optional - if True, represent large numbers in scientific exponent notation. ## format_int(n: int, grouping: bool = True) -> str ### Description Format an integer with grouping (thousands separator). ### Parameters * **grouping** (bool) - Optional - add thousands separator. Defaults to True. ### Notes If you need to show an integer without grouping, you don’t need l10n. All languages display whole numbers in arabic numerals in the same way. ``` -------------------------------- ### Extract strings for translation Source: https://github.com/orsinium-labs/l10n/blob/master/docs/quickstart.md Use the l10n CLI to extract translatable strings from your Python code for a specific target language. ```bash python3 -m l10n extract --lang uk ``` -------------------------------- ### Number Parsing Functions Source: https://github.com/orsinium-labs/l10n/blob/master/docs/api.md Functions to parse formatted strings back into numbers. ```APIDOC ## parse_float(s: str) -> float ### Description Convert string generated by Locale.format_float back into float. ### Parameters * **s** (str) - Required - The string to parse. ## parse_int(s: str) -> int ### Description Convert string generated by Locale.format_int back into int. ### Parameters * **s** (str) - Required - The string to parse. ``` -------------------------------- ### l10n.Locale Class Source: https://github.com/orsinium-labs/l10n/blob/master/docs/api.md Represents a specific locale and provides methods for translation and formatting. ```APIDOC ## Class l10n.Locale ### Description Represents a specific locale and provides methods for translation and formatting. ### Methods #### reset_cache() -> None Reset all the cached values for the locale object. Use it if you need to reload the mo file. #### get(message: str, context: str | None = None, plural: str | None = None, n: int | None = None, comment: str = '') -> str Get translation for the message from the catalog (mo file). ### Parameters #### Path Parameters - **message** (str) - Required - the message to translate. If no translation found, the message itself will be used. Represented as msgid in PO files. - **context** (str | None) - Optional - kind of namespace for translations, used to distinguish two messages that may have a different translation depending on the context they are used in. Represented as msgctxt in PO files. - **plural** (str | None) - Optional - the default value if n > 1 and no translation found. It also indicates for translator that the message should have plural translations. Represented as msgid_plural in PO files. - **n** (int | None) - Optional - the number used to pick a plural form for the translation. - **comment** (str) - Optional - not used in runtime but included in PO files. Use it to provide additional information for translators. #### format_date(date: date) -> str Format date. You need the locale do be compiled in your OS. #### format_time(time: time) -> str Format time. You need the locale do be compiled in your OS. #### format_datetime(dt: datetime) -> str Format date and time. You need the locale do be compiled in your OS. #### format_month(n: int, abbreviate: bool = False) -> str Format the month number into its name. You need the locale do be compiled in your OS. ### Parameters #### Path Parameters - **n** (int) - Required - the month number. - **abbreviate** (bool) - Optional - Use the short version of the month name. Default: False #### format_dow(n: int, abbreviate: bool = False, sunday: int = 0) -> str Format the day of week. You need the locale do be compiled in your OS. ### Parameters #### Path Parameters - **n** (int) - Required - the day of week number. - **abbreviate** (bool) - Optional - Use the short version of the DoW. Default: False - **sunday** (int) - Optional - Depending on your country and if you count from 0 or 1, different numbers correspond to a different day of week. The sunday argument allows you to specify what number is Sunday for you. By default, it is 0 assuming that the first DoW is Sunday and you count days from 0 to 6. #### format_currency(val: int | float | Decimal, symbol: bool = True, international: bool = False, grouping: bool = False) -> str Format a price in the locale currency. 1. The locale currency symbol will be added. 2. The currency symbol will be placed in the right position. 3. The minus for negative numbers will be placed in the right position. 4. The locale decimal separator will be used. ### Parameters #### Path Parameters - **val** (int | float | Decimal) - Required - the value to format. - **symbol** (bool) - Optional - include the currency symbol. Default: True - **international** (bool) - Optional - use international currency symbol. Default: False - **grouping** (bool) - Optional - add thousands separator. Default: False ### Properties #### language : str The language of the Locale. #### currency_symbol : str The symbol used to denote the currency. You need the locale do be compiled in your OS. #### decimal_dot : str The symbol used to separate whole and fractional parts in decimal numbers. Also known as decimal dot, decimal comma, radix character. You need the locale do be compiled in your OS. #### thousands_separator : str The symbol used to separate groups of digits in big numbers. In most of the languages, it separates groups of three digits. In some locales, though, digits are grouped by 4. https://en.wikipedia.org/wiki/Decimal_separator. You need the locale do be compiled in your OS. ``` -------------------------------- ### Handling Plural Forms in Translations Source: https://github.com/orsinium-labs/l10n/blob/master/docs/advanced.md Pass the argument `n` to `Locale.get` to select the correct plural form for a translation. The `plural` argument can specify a default message for non-singular forms when no translation is found. ```python n_msgs = 13 locale = Locales()['ru'] msg = locale.get('{n} message(s)', n=n_msgs).format(n=n_msgs) ``` ```python msg = locale.get('{n} message', n=n_msgs, plural='{n} messages').format(n=n_msgs) ``` -------------------------------- ### Translation Functions Source: https://github.com/orsinium-labs/l10n/blob/master/docs/api.md Functions to translate country, currency, and language names. ```APIDOC ## translate_country(country_name: str) -> str ### Description Translate country name from English to the given language. ### Parameters * **country_name** (str) - Required - The country name in English. ### Notes Follows ISO 3166-1. Requires iso-codes package to be installed. ## translate_currency(currency_name: str) -> str ### Description Translate currency name from English to the given language. ### Parameters * **currency_name** (str) - Required - The currency name in English. ### Notes Follows ISO 4217. Requires iso-codes package to be installed. ## translate_language(language_name: str) -> str ### Description Translate language name from English to the given language. ### Parameters * **language_name** (str) - Required - The language name in English. ### Notes Follows ISO 639-2 and ISO 639-3. Requires iso-codes package to be installed. ``` -------------------------------- ### Manage Locale Cache Source: https://context7.com/orsinium-labs/l10n/llms.txt Control caching behavior for locales. Allows resetting the cache for a specific locale to reload translations or use `get_cached` for LRU caching. ```python from l10n import Locales locales = Locales() # Normal usage - locale content is cached on first access loc = locales['en'] msg = loc.get('Hello') # MO file loaded and cached # Reset cache for a specific locale (reload translations) loc.reset_cache() # Get new instance without old cache fresh_locales = Locales() fresh_loc = fresh_locales['en'] # Loads fresh from disk # Use get_cached for LRU caching (16 most recent locales) loc = locales.get_cached('en') # Cached across calls ``` -------------------------------- ### Include Additional Strings with TYPE_CHECKING Source: https://github.com/orsinium-labs/l10n/blob/master/docs/advanced.md Use the TYPE_CHECKING block to include strings in translations that are not directly evaluated at runtime. This ensures that `l10n extract` can find these strings for localization purposes. ```python from typing import TYPE_CHECKING if TYPE_CHECKING: from l10n import Locales loc = Locales()['en'] loc.get('hello world') loc.get('oh hi mark') ``` -------------------------------- ### Parse Formatted Numbers Source: https://context7.com/orsinium-labs/l10n/llms.txt Parse strings formatted according to locale conventions back into numerical types (float and integer). ```python # Parse formatted numbers back formatted = loc.format_float(1234.56, grouping=True) value = loc.parse_float(formatted) # 1234.56 formatted_int = loc.format_int(1234567) value_int = loc.parse_int(formatted_int) # 1234567 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.