🔍 Code Extractor

class Language

Maturity: 46

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

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sites/language.py
Lines:
4 - 21
Complexity:
simple

Purpose

The Language class encapsulates information about a natural language, including its human-readable display name, standardized language tag (culture name), and numeric locale identifier. It inherits from ClientValue, suggesting it's used for client-side data representation in the Office365 API context. This class provides a structured way to handle language metadata in applications that need to work with multiple languages or locales.

Source Code

class Language(ClientValue):
    """Represents a natural language."""

    def __init__(self, display_name=None, language_tag=None, lcid=None):
        """
        :param str display_name: Specifies the name of the language as displayed in the user interface.
        :param str language_tag: Specifies the corresponding culture name for the language.
        :param int lcid: Specifies the language code identifier (LCID) for the language.
        """
        self.DisplayName = display_name
        self.LanguageTag = language_tag
        self.Lcid = lcid

    def __str__(self):
        return self.DisplayName

    def __repr__(self):
        return "{0}: {1}".format(self.DisplayName, self.LanguageTag)

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

display_name: The human-readable name of the language as it should appear in user interfaces (e.g., 'English', 'Español'). Optional parameter that defaults to None if not provided.

language_tag: The standardized culture/language tag following conventions like BCP 47 (e.g., 'en-US', 'es-ES', 'fr-FR'). This identifies the language and optionally the region. Optional parameter that defaults to None.

lcid: The Language Code Identifier, a numeric value used by Microsoft systems to identify languages and locales (e.g., 1033 for English-US, 1036 for French-France). Optional integer parameter that defaults to None.

Return Value

Instantiation returns a Language object with three attributes (DisplayName, LanguageTag, Lcid) set to the provided values or None. The __str__ method returns the DisplayName as a string. The __repr__ method returns a formatted string combining DisplayName and LanguageTag in the format 'DisplayName: LanguageTag'.

Class Interface

Methods

__init__(display_name=None, language_tag=None, lcid=None)

Purpose: Initializes a new Language instance with optional display name, language tag, and locale identifier

Parameters:

  • display_name: Optional string representing the human-readable name of the language
  • language_tag: Optional string representing the standardized culture/language tag
  • lcid: Optional integer representing the Microsoft Language Code Identifier

Returns: None (constructor)

__str__() -> str

Purpose: Returns the string representation of the Language object using its display name

Returns: The DisplayName attribute value as a string (may be None if not set)

__repr__() -> str

Purpose: Returns a detailed string representation combining display name and language tag for debugging

Returns: A formatted string in the format 'DisplayName: LanguageTag'

Attributes

Name Type Description Scope
DisplayName str or None The human-readable name of the language as displayed in user interfaces instance
LanguageTag str or None The standardized culture/language tag (e.g., 'en-US', 'fr-FR') following BCP 47 conventions instance
Lcid int or None The Microsoft Language Code Identifier, a numeric value identifying the language/locale instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue

class Language(ClientValue):
    def __init__(self, display_name=None, language_tag=None, lcid=None):
        self.DisplayName = display_name
        self.LanguageTag = language_tag
        self.Lcid = lcid
    
    def __str__(self):
        return self.DisplayName
    
    def __repr__(self):
        return "{0}: {1}".format(self.DisplayName, self.LanguageTag)

# Create a Language instance for English (United States)
english_us = Language(
    display_name='English (United States)',
    language_tag='en-US',
    lcid=1033
)

# Access attributes
print(english_us.DisplayName)  # Output: English (United States)
print(english_us.LanguageTag)  # Output: en-US
print(english_us.Lcid)  # Output: 1033

# String representations
print(str(english_us))  # Output: English (United States)
print(repr(english_us))  # Output: English (United States): en-US

# Create with partial information
french = Language(display_name='French', language_tag='fr')
print(french.Lcid)  # Output: None

Best Practices

  • All constructor parameters are optional, but for meaningful use, at least display_name should be provided to make the object useful in UI contexts.
  • The class uses PascalCase for attribute names (DisplayName, LanguageTag, Lcid) which follows Microsoft/Office365 API conventions rather than Python's snake_case convention.
  • This is an immutable-style data class - attributes are set during initialization and typically not modified afterward.
  • The __str__ method returns only DisplayName, which may be None if not set during initialization - handle potential None values when using str(language_obj).
  • When creating Language instances for Microsoft Office365 integration, ensure LCID values match Microsoft's official locale identifiers.
  • The language_tag should follow BCP 47 standards (e.g., 'en-US', 'zh-CN') for maximum compatibility with international standards.
  • Since this inherits from ClientValue, it's designed to be serialized/deserialized for API communication - avoid adding complex objects as attributes.

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class Label 69.6% similar

    A class representing a localized label with name, default status, and language tag information, inheriting from ClientValue.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/terms/label.py
  • class LocaleInfo 68.7% similar

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

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/locale_info.py
  • class LanguageCollection 67.0% similar

    A collection class that manages and provides access to a set of SPLanguage objects, inheriting from Entity base class.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sites/language_collection.py
  • class LocalizedName 65.6% similar

    Represents a localized name used in a term store, storing both the name text and its language tag to identify names in different localized languages.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/taxonomy/sets/name.py
  • class CurrencyInformation 64.6% 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
← Back to Browse