🔍 Code Extractor

class LocaleInfo

Maturity: 48

A data class representing locale information for a signed-in user, including their preferred language and country/region settings.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/locale_info.py
Lines:
4 - 19
Complexity:
simple

Purpose

LocaleInfo encapsulates locale-related information for a user in the Office 365 ecosystem. It stores both a human-readable display name (e.g., 'English (United States)') and a standardized locale code (e.g., 'en-us') following ISO 639-1 and ISO 3166-1 alpha-2 standards. This class inherits from ClientValue, making it suitable for serialization and transmission in Office 365 API interactions. It provides a simple container for locale data that can be used to configure user preferences, format content appropriately, or filter resources based on language and region.

Source Code

class LocaleInfo(ClientValue):
    """Information about the locale, including the preferred language and country/region, of the signed-in user."""

    def __init__(self, display_name=None, locale=None):
        """
        :param str display_name: A name representing the user's locale in natural language,
            for example, "English (United States)".
        :param str locale: A locale representation for the user, which includes the user's preferred language
            and country/region. For example, "en-us". The language component follows 2-letter codes as defined in
            ISO 639-1, and the country component follows 2-letter codes as defined in ISO 3166-1 alpha-2.
        """
        self.displayName = display_name
        self.locale = locale

    def __repr__(self):
        return self.locale

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

display_name: A human-readable string representing the user's locale in natural language format, such as 'English (United States)', 'French (France)', or 'Spanish (Mexico)'. This parameter is optional and defaults to None if not provided. It's intended for display purposes in user interfaces.

locale: A standardized locale code string following the format 'language-country' where language is a 2-letter ISO 639-1 code (e.g., 'en', 'fr', 'es') and country is a 2-letter ISO 3166-1 alpha-2 code (e.g., 'us', 'gb', 'mx'). Examples include 'en-us', 'fr-fr', 'es-mx'. This parameter is optional and defaults to None if not provided. It represents the technical locale identifier used for programmatic operations.

Return Value

Instantiation returns a LocaleInfo object with displayName and locale attributes set to the provided values (or None if not provided). The __repr__ method returns the locale string when the object is printed or converted to a string representation.

Class Interface

Methods

__init__(self, display_name=None, locale=None)

Purpose: Constructor that initializes a LocaleInfo instance with optional display name and locale code

Parameters:

  • display_name: Optional string representing the locale in natural language (e.g., 'English (United States)')
  • locale: Optional string with standardized locale code following ISO standards (e.g., 'en-us')

Returns: None (constructor)

__repr__(self) -> str

Purpose: Returns a string representation of the LocaleInfo object using the locale code

Returns: The locale string (e.g., 'en-us') or None if locale was not set

Attributes

Name Type Description Scope
displayName str or None Human-readable name representing the user's locale in natural language, such as 'English (United States)' or 'French (France)' instance
locale str or None Standardized locale code in 'language-country' format following ISO 639-1 and ISO 3166-1 alpha-2 standards (e.g., 'en-us', 'fr-fr') instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue

class LocaleInfo(ClientValue):
    def __init__(self, display_name=None, locale=None):
        self.displayName = display_name
        self.locale = locale
    
    def __repr__(self):
        return self.locale

# Create a LocaleInfo instance for US English
user_locale = LocaleInfo(
    display_name='English (United States)',
    locale='en-us'
)

# Access attributes
print(user_locale.displayName)  # Output: English (United States)
print(user_locale.locale)  # Output: en-us
print(user_locale)  # Output: en-us (uses __repr__)

# Create with only locale code
minimal_locale = LocaleInfo(locale='fr-fr')
print(minimal_locale)  # Output: fr-fr

# Create empty instance
empty_locale = LocaleInfo()
print(empty_locale.locale)  # Output: None

Best Practices

  • Always provide both display_name and locale parameters when creating instances for complete locale information, though both are optional.
  • Use standard ISO 639-1 language codes and ISO 3166-1 alpha-2 country codes for the locale parameter to ensure compatibility with Office 365 APIs.
  • The locale format should follow 'language-country' pattern with lowercase letters and hyphen separator (e.g., 'en-us', not 'en_US' or 'EN-US').
  • This class is immutable after instantiation - attributes can be modified but there are no methods to update them in a controlled way.
  • The __repr__ method returns only the locale string, not the display_name, so use the displayName attribute directly when you need the human-readable format.
  • This class inherits from ClientValue, which likely provides serialization capabilities for Office 365 API communication, so it's designed to be used as part of larger API request/response objects.
  • Handle None values appropriately when accessing attributes if the instance was created without providing all parameters.

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class Language 68.7% similar

    A data class representing a natural language with its display name, language tag, and locale identifier (LCID).

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sites/language.py
  • class CurrencyInformation 68.2% similar

    A data class that encapsulates currency information including display formatting, language/culture settings, and locale identifiers for UI presentation.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/lists/currency_information.py
  • class ParticipantInfo 64.5% similar

    A data class that stores additional properties about a participant's identity, specifically their country code location information.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/communications/calls/participant_info.py
  • class TimeZoneInformation 62.5% similar

    A data class representing time zone information with support for Windows and IANA (Olson) time zone formats.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/timezone_information.py
  • class TranslationItemInfo 60.2% similar

    A data class representing information about a previously submitted translation item in SharePoint's translation service.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/translation/item_info.py
← Back to Browse