\LanguagePrefix
The LanguagePrefix extension allows you to create links with a language prefix for multilingual websites, using one domain only, that can be parsed by the PrefixModelAsController. Example:
www.mydomain.com/en/
www.mydomain.com/nl
PrefixModelAsController replaces ModelAsController and RootURLController in
the YAML routes.
<h2>Configuration</h2>
<h3>Enable the LanguagePrefix module</h3>
Add this to your languageprefix.yml
SiteTree:
extensions:
['LanguagePrefix']
Synopsis
class LanguagePrefix
extends DataExtension
{
- // members
- public static $locale_prefix_map;
- // methods
- public static string get_prefix()
- public static string get_locale_from_prefix()
- protected static void load_prefix_map()
- public void __construct()
- public void PrefixLink()
- public static string get_homepage_link_by_locale()
- public void updateRelativeLink()
- public void updateCMSFields()
- public string BaseLinkForLocale()
- public void HomeLink()
- public SiteTree alternateGetByLink()
- public static boolean valid_prefix()
- public void getPagePrefix()
Hierarchy
Extends
- DataExtension
Members
public
- $locale_prefix_map
—
array
language prefix for translatable sites format: locale => prefix: 'en_US' => 'en'
Methods
protected
- load_prefix_map() — Get the locale -> prefix map from languageprefix.yml
public
- __construct() — Load the prefix map before anything else happens
- BaseLinkForLocale() — Return a link to the homepage for the current locale
- HomeLink()
- PrefixLink() — Deprecated: use Link() instead.
- alternateGetByLink() — Get the prefix out of the way.
- getPagePrefix() — Returns the prefix name for this page Useful for showing the prefix name rather than the full nice name or code
- get_homepage_link_by_locale() — Get the RelativeLink value for a home page in another locale. This is found by searching for the default home page in the default language, then returning the link to the translated version (if one exists).
- get_locale_from_prefix() — return the $locale based on the language prefix. If no locale is given, the default Translatable locale is assumed.
- get_prefix() — return the language prefix for the current locale. If no locale is given, the default Translatable locale is assumed.
- updateCMSFields() — Update the URLsegment in the CMS so it shows the correct language prefix in the URL.
- updateRelativeLink() — Add the language prefix to the relative link. Be sure to remove the homepage $URLSegment.
- valid_prefix() — Is the prefix a valid locale? (@see alternateGetByLink)