-
-
Save alabamenhu/a84cec3a6f976302368525b26fc74907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To enable known localization frameworks, include their identifiers in the use statement | |
use Intl::Localization <xliff fluent>; | |
# Using the module inserts a dynamic variable used for settings | |
# $*INTL-LOCALIZATION-DOMAIN <-- a "grouping" of files. Only used where | |
# $*INTL-LOCALIZATION-LANGUAGE | |
# Tells the framework that files will be structure like | |
# foo/en.ftl | |
# foo/es-ES.ftl | |
add-localization-basepath 'foo/' ~ * ~ '.ftl'; | |
# Tells the framework that files will be structure like | |
# foo/en/bar.ftl | |
# foo/es-ES/bar.ftl | |
add-localization-basepath 'foo/' ~ * ~ '/bar.ftl'; | |
# Tells the framework that even though the file extension | |
# is xml, treat it as an xliff type | |
add-localization-basepath 'foo/' ~ * ~ '.xml', :type<xliff>; | |
# Tells the framework that even though the file extension | |
# is xml, treat it as an xliff type | |
add-localization-basepath 'foo/' ~ * ~ '.xml', :type<xliff>; | |
# Tells the framework that the localization files are in the | |
# resource folder | |
add-localization-basepath 'foo/' ~ * ~ '.ftl', :resource; | |
# Tells the framework to use a separate named manager | |
# is xml, treat it as an xliff type | |
add-localization-basepath 'foo/' ~ * ~ '.xml', :domain<websiteA>; | |
# Retrieve a localized string | |
localize "message-id"; | |
# Retrieve a localized string passing in an argument | |
# (to be interpreted by each localization engine) | |
localize "message-id", $pos1, $pos2, :$named1, :$named2; | |
# by default, localizations will work as expected, but the current | |
# message settings can be adjusted on the fly by using | |
localize "title"; # "Webseitentitel" (or whatever was loaded without a :domain arg) | |
localization-domain 'website'; # switch away from the default set of messages | |
localization-language 'en-US'; # switch away from the default language (user-language or inherited) | |
localize "title"; # "Website Title" (loaded from files with :domain<website>, and in English) | |
# but these settings can lexically scoped (and follow call scope!) by using | |
localization-domain { | |
localization-domain 'different-website'; | |
localize "title"; # "Title of Different Website" | |
localization-language 'es-ES'; | |
localize "title"; # "Título de sitio distinto" | |
} | |
localize "title"; # Back to "Website Title"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment