Package: hugo-gettext
hugo-gettextI18n with gettext for Hugo.Currently compliant with Hugo 0.110.0.Installpipinstallhugo-gettextUsageThere are three commands corresponding to three steps thathugo-gettextsupports:hugo-gettext extractextracts messages from source files (files in the
source language) to one or many POT files;hugo-gettext compilecompiles PO files to binary MO files;hugo-gettext generateuses MO files to generate target files (files in
target languages).These are types of text thathugo-gettextcan extract messages from and can
generate in target languages:Front matter and content in content files;Strings in string file (i.e. "translation table") ini18nfolderotherkeysSupportcommentMenu item names, site title, and site description in site config file:
all inlanguages.enconfig key:title:titledescription:params.descriptionmenu:menu.main.<entry>.nameData in data files: processed as Markdown (front matter text aren't
processed as Markdown).Each project can specify multiple text domains to work with (i.e. messages are
extracted to multiple POT files and subsequently multiple PO files are
available to use for generation), however all types of text outside content
files always belong to a default domain which is derived from a name that each
project must have. Content files can be associated with the default domain or
custom domains.Directory structure in each stepCompilationFrom a folder containing subdirectories with PO files inside,
in the form of<dir>/<lang_code>/<domain>.poTo alocalefolderStructure:locale/<lang_code>/LC_MESSAGES/<domain>.poGenerationConditions in front matterhugo_lang_codes are prepended to absolute links inaliasesdict in front matterHow data file generation worksRequirement for a language to be qualified
(a config block is added and data files are generated, string file is generated anyway):there's no content file to translate but string file is translated, orthere are content files to translate and some files are translatedA content file is considered translated ifThe front matter is translated, orThere's nothing in the content, orThe translation rate of the content is higher than 50%MarkdownCommonMark compliant. All core Markdown elements are supported, as well as
table, and definition list.Some notes about how different elements are handled:Inlines: hard line breaks are replaced with, newlines and consecutive spaces are not kept;Content of each HTML block isn't parsed into finer tokens but processed as a whole;ShortcodesIf the string contains only one shortcodeNewlines are kept for arguments quoted with backtickshg_stop shortcode to stop processing a content fileAttributesConfigurationpackage:Project-Id-Versionin POT metadatadefault_domain_namereport_addressandteam_address:Report-Msgid-Bugs-ToandLanguage-Teamin POT metadataexcluded_keys: in front matterexcluded_data_keys: in data filesrtl_langsshortcodes: can use*wildcard to indicate all shortcodesCustom functionsThe path of the file should be passed as an argument to the command line with-cor--customsoption,
or set in the config file withcustomskey.The following functions are called to makedefault_domain_name,excluded_keys,report_address,team_address, andrtl_langsattributes ofConfig:get_default_domain_name: will be called withpackageas an argument, returnspackageby defaultget_custom_excluded_keys: returns an empty set by defaultget_pot_fields: returns a dictionary of'report_address'and'team_address'keysget_rtl_langs: returns a list of codes of RTL languagesTwo functions are called during the generation step:load_lang_names: returns an empty dictionary by defaultconvert_lang_code: function to convert gettext language codes to Hugo language codes,
returns gettext language codes by defaultDevelopmentWith Condacondaenvcreate-fenvironment.yml
condaactivatehg
poetryinstall