PeterO.Mail.LanguageTags

## PeterO.Mail.LanguageTags

public static class LanguageTags

Contains methods for parsing and matching language tags.

Member Summary

### GetLanguageList

public static System.Collections.Generic.IList GetLanguageList(
    string str);

Parses a language list from a Content-Language header field.

Parameters:

Return Value:

A list of language tags. Returns an empty list if str is null or the empty string, or null if str syntactically invalid.

### GetRangeListWithQuality

public static System.Collections.Generic.IList GetRangeListWithQuality(
    string str);

Parses a language range list from an Accept-Language header field.

Parameters:

Return Value:

A list of language ranges with their associated qualities. The list will be sorted in descending order by quality; if two or more language ranges have the same quality, they will be sorted in the order in which they appeared in the given string. Returns null if str is null or syntactically invalid.

### IsLanguageRange

public static bool IsLanguageRange(
    string str);

Returns whether the given string is a basic language range under RFC 4647. Examples include “*”, “en-us”, and “fr”.

Parameters:

Return Value:

true if the given string is a basic language range; otherwise, false .

### IsLanguageRange

public static bool IsLanguageRange(
    string str,
    bool extended);

Returns whether the given string is a basic or extended language range under RFC 4647. Examples of basic (and extended) language ranges include “”, “en-us”, and “fr”. Examples of extended language ranges include “-de” and “it-*”.

Parameters:

Return Value:

true if the given string is a basic language range (depending on the extended parameter); otherwise, false .

### IsPotentiallyValidLanguageTag

public static bool IsPotentiallyValidLanguageTag(
    string str);

Returns true if (1) the given string is a well-formed language tag under RFC 5646 (that is, the string follows the syntax given in section 2.1 of that RFC), and (2) the language tag contains at most one extended language subtag, no variant subtags with the same value, and no extension singleton subtags with the same value.

Parameters:

Return Value:

true , if the string meets the conditions given in the summary, false otherwise.

### LanguageTagCase

public static string LanguageTagCase(
    string str);

Sets the given language tag to the case combination recommended by RFC 5646. For example, “en-us” becomes “en-US”, and “zh-hant” becomes “zh-Hant”.

Parameters:

Return Value:

A text string in the recommended case combination, or null if str is null.

### LanguageTagFilter

public static System.Collections.Generic.IList LanguageTagFilter(
    System.Collections.Generic.IList ranges,
    System.Collections.Generic.IList languages);

Finds the language tags that match a priority list of basic language ranges.

Parameters:

Return Value:

A list of language tags that match the given range, in descending order of preference.

Exceptions:

### LanguageTagFilter

public static System.Collections.Generic.IList LanguageTagFilter(
    System.Collections.Generic.IList ranges,
    System.Collections.Generic.IList languages,
    bool extended,
    bool matchStarAtEnd);

Finds the language tags that match a priority list of language ranges.

Parameters:

Return Value:

A list of language tags that match the given range, in descending order of preference.

Exceptions:

### LanguageTagLookup

public static string LanguageTagLookup(
    string range,
    System.Collections.Generic.IList languages,
    string defaultValue);

Does a language tag lookup (under RFC 4647) for a matching language tag.

Parameters:

Return Value:

The matching language tag, or the parameter defaultValue if there is no matching language tag.

Exceptions:

### LanguageTagLookup

public static string LanguageTagLookup(
    string range,
    System.Collections.Generic.IList languages,
    string defaultValue,
    bool extended);

Does a language tag lookup (under RFC 4647) for a matching language tag.

Parameters:

Return Value:

The matching language tag, or the parameter defaultValue if there is no matching language tag.

Exceptions:

### LanguageTagLookup

public static string LanguageTagLookup(
    System.Collections.Generic.IList ranges,
    System.Collections.Generic.IList languages,
    string defaultValue);

Does a language tag lookup (under RFC 4647) for a matching language tag.

Parameters:

Return Value:

The matching language tag, or the parameter defaultValue if there is no matching language tag.

Exceptions:

### LanguageTagLookup

public static string LanguageTagLookup(
    System.Collections.Generic.IList ranges,
    System.Collections.Generic.IList languages,
    string defaultValue,
    bool extended);

Does a language tag lookup (under RFC 4647) for a matching language tag.

Parameters:

Return Value:

The matching language tag, or the parameter defaultValue if there is no matching language tag.

Exceptions:

### MatchesLanguageTag

public static bool MatchesLanguageTag(
    string range,
    string tag);

Determines whether the given language tag matches the given language range.

Parameters:

Return Value:

true if the language tag matches the language range by the filtering method under RFC 4647; otherwise, false .

Exceptions:

Back to MailLib start page.