class Language
A data class representing a natural language with its display name, language tag, and locale identifier (LCID).
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/sites/language.py
4 - 21
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 languagelanguage_tag: Optional string representing the standardized culture/language taglcid: 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.
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Label 69.6% similar
-
class LocaleInfo 68.7% similar
-
class LanguageCollection 67.0% similar
-
class LocalizedName 65.6% similar
-
class CurrencyInformation 64.6% similar