banffprocessor.nls package#

Submodules#

banffprocessor.nls.nls module#

Native Language Support (NLS) for the Banff Processor.

Implement bilingual message support via gettext. This module was copied from Banff and adapted for the Banff Proessor.

banffprocessor.nls.nls.custom_gettext(a: str) str[source]#

Implement costom gettext function.

To be aliased as _() when used by other modules.

Uses the gettext instance corresponding to the active language, defaulting to English.

Why not use gettext.install()?
  • it goes against a tsunami of recommendations against modifying builtins

  • it plays poorly with intellisense

  • it makes the origin of the _() function untraceable to new developers

  • it may affect (or be affected by) 3rd party Python Code - installed _() can become broken (redefined, undefined) when running interactively.

banffprocessor.nls.nls.determine_language() SupportedLanguage[source]#

Try to determine user’s language and return corresponding SupportedLanguage member.

Calls locale.getlocale(), performs custom search on language portion of return value for French and English language codes as observed in the wild (i.e., Windows AVD, Linux VM).

Users can affect the outcome using locale.setlocale() prior to importing the package. For example, to use French run locale.setlocale(locale.LC_CTYPE, “fr_CA”)

Returns associated SupportedLanguage member.

.UNKNOWN if language not supported

about locale.getlocale()

[non RFC1766 language codes](python/cpython#82986) - Around Python 3.8 on Windows, this function started returning codes

like ‘English_United States’, instead of ‘en_US’

about locale.getdefaultlocale()

[getdefaultlocale() deprecated](python/cpython#31206) - tempting to use since it returns rfc1755 codes seemingly in all versions - not used because it’s deprecated in Python 3.13

banffprocessor.nls.nls.get_language() SupportedLanguage[source]#

Return the active language.

banffprocessor.nls.nls.set_language(lang: SupportedLanguage | None = None) None[source]#

Set the active language to lang, or determine language based on locale.

Specify a member of banffprocessor.SupportedLanguage for lang.

The value set by this function will affect log message output. It may be referred to (via get_language()) by other modules in order to implement NLS.

Module contents#

Native Language Support (bilingual messages) for the Banff Processor.

class banffprocessor.nls.SupportedLanguage(*values)[source]#

Bases: Enum

Languages supported by Native Language Support module.

Enums have the form <name> = <[list, of, values]> Users should refer to Enums by member-name, like SupportedLanguage.en.

Internally, .value is used to associate a list of language tags with a supported language.

<name> - only use valid RFC1766 language tags <value> - should be a list of associated language tags

these tags should include both RFC1766 tags as well non RFC1766 tags observed in the wild (…on Windows)

UNKNOWN = []#
en = ['en', 'english']#
fr = ['fr', 'french']#
banffprocessor.nls.get_language() SupportedLanguage[source]#

Return the active language.

banffprocessor.nls.set_language(lang: SupportedLanguage | None = None) None[source]#

Set the active language to lang, or determine language based on locale.

Specify a member of banffprocessor.SupportedLanguage for lang.

The value set by this function will affect log message output. It may be referred to (via get_language()) by other modules in order to implement NLS.