Interface LanguageManager


  • @ProviderType
    public interface LanguageManager
    Provides a service for content languages. Note that this has nothing to do with the i18n of the WCM itself.
    • Field Detail

      • ISO_PROP_NAME

        static final java.lang.String ISO_PROP_NAME
        relative path of the language property of a hierarchy node.
        See Also:
        Constant Field Values
      • IS_LANGUAGE_ROOT_PROP_NAME

        static final java.lang.String IS_LANGUAGE_ROOT_PROP_NAME
        relative path of the language root property of a hierarchy node.
        See Also:
        Constant Field Values
    • Method Detail

      • getIsoCountry

        java.lang.String getIsoCountry​(java.util.Locale language)
        Returns the country iso code for the given locale. if the country is not already defined in the locale a configured default value is returned. If no iso code exists, an empty string is returned.
        Parameters:
        language - the language locale to retrieve the country from
        Returns:
        a country iso code or ""
      • getAdjacentLanguageInfo

        java.util.Map<Language,​LanguageManager.Info> getAdjacentLanguageInfo​(ResourceResolver resolver,
                                                                                   java.lang.String path)
        Returns a map of language information for each language filled with information if respective hierarchy or content exists for that language.
        Parameters:
        resolver - resource resolver
        path - path to check
        Returns:
        map of information or null if the given path does not reside on or below a language root.
        Since:
        5.4
        See Also:
        LanguageUtil.getLanguageRoot(String)
      • getLanguage

        java.util.Locale getLanguage​(Resource res)
        Returns the language for the given resource. Note that this method only uses the path names for the determination of the language.
        Parameters:
        res - resource
        Returns:
        the locale or null if not determinable
      • getCqLanguage

        Language getCqLanguage​(Resource res)
        Returns the language for the given resource. Note that this method only uses the path names for the determination of the language.
        Parameters:
        res - resource
        Returns:
        the locale or null if not determinable
        Since:
        5.4
      • getLanguage

        java.util.Locale getLanguage​(Resource res,
                                     boolean respectContent)
        Returns the language for the given resource. The path of the resource is analyzed to find a matching iso code. If no iso code can be found, null is returned unless respectContent is true. then the resources ancestors (including the given) one is searched for a ISO_PROP_NAME property.
        Parameters:
        res - resource
        respectContent - if false only the path is analyzed
        Returns:
        the locale or null if not determinable
        Since:
        5.4
      • getCqLanguage

        Language getCqLanguage​(Resource res,
                               boolean respectContent)
        Returns the language for the given resource. The path of the resource is analyzed to find a matching iso code. If no iso code can be found, null is returned unless respectContent is true. then the resources ancestors (including the given) one is searched for a ISO_PROP_NAME property.
        Parameters:
        res - resource
        respectContent - if false only the path is analyzed
        Returns:
        the locale or null if not determinable
        Since:
        5.4
      • getLanguageRoot

        Page getLanguageRoot​(Resource res)
        Returns the language root page for the given resource. Note that currently only the path names are respected for the determination of the language.
        Parameters:
        res - resource
        Returns:
        the language root page or null if not determinable
      • getLanguageRoot

        @Nullable
        Page getLanguageRoot​(Resource res,
                             boolean respectContent)
        Returns the language root page for the given resource. If respectContent is true, then the resources ancestors (including the given one) are searched for a IS_LANGUAGE_ROOT_PROP_NAME property. If the property is true, ISO_PROP_NAME is used to determine language root. If the IS_LANGUAGE_ROOT_PROP_NAME property is false or the ISO_PROP_NAME property is not found or respectContent is false, the path of the resource is analyzed to find a matching iso code. If no iso code can be found, null is returned.
        Parameters:
        res - resource
        respectContent - if false only the path is analyzed
        Returns:
        the language root page or null if not determinable
        Since:
        6.4
      • getLanguageRootResource

        Resource getLanguageRootResource​(Resource res)
        Returns the language root resource for the given resource. Note that currently only the path names are respected for the determination of the language.
        Parameters:
        res - the resource
        Returns:
        the language root resource or null if not determinable
      • getLanguageRootResource

        @Nullable
        Resource getLanguageRootResource​(Resource res,
                                         boolean respectContent)
        Returns the language root resource for the given resource. If respectContent are true, then the resources ancestors (including the given one) is searched for a IS_LANGUAGE_ROOT_PROP_NAME property. If the property is true, ISO_PROP_NAME is used to determine language root. If the IS_LANGUAGE_ROOT_PROP_NAME property is false or the ISO_PROP_NAME property is not found or respectContent is false, the path of the resource is analyzed to find a matching iso code. If no iso code can be found, null is returned.
        Parameters:
        res - the resource
        respectContent - if false only the path is analyzed
        Returns:
        the language root resource or null if not determinable
        Since:
        6.4
      • getLanguages

        java.util.Collection<java.util.Locale> getLanguages​(ResourceResolver resolver,
                                                            java.lang.String path)
        Returns a collection of root languages for the given page. Note that only the path names are respected for the determination of the language.
        Parameters:
        resolver - resource resolver
        path - path of the current page
        Returns:
        collection of root languages
      • getCqLanguages

        java.util.Collection<Language> getCqLanguages​(ResourceResolver resolver,
                                                      java.lang.String path)
        Returns a collection of root languages for the given page. Note that only the path names are respected for the determination of the language.
        Parameters:
        resolver - resource resolver
        path - path of the current page
        Returns:
        collection of root languages
        Since:
        5.4
      • getLanguageRoots

        java.util.Collection<Page> getLanguageRoots​(ResourceResolver resolver,
                                                    java.lang.String path)
        Returns a collection of language root pages for the given page. Note that only the path names are respected for the determination of the language.
        Parameters:
        resolver - resource resolver
        path - path of the current page
        Returns:
        collection of language root paths
      • getLanguageRootResources

        java.util.Collection<Resource> getLanguageRootResources​(ResourceResolver resolver,
                                                                java.lang.String path)
        Returns a collection of Resource objects which act as language roots for the resource at the given path.
        Parameters:
        resolver - a ResourceResolver used to access the repository
        path - the path of the current page
        Returns:
        a collection of language root resources
      • getLanguageRootResources

        java.util.Collection<Resource> getLanguageRootResources​(ResourceResolver resolver,
                                                                java.lang.String path,
                                                                boolean respectContent)
        Returns a collection of Resource objects which act as language roots for the resource at the given path. For example, consider the following structure where language roots would be searched a level up or down.
         /content/example/language-masters
         +-- en
         +-- emea
         |   +-- de
         |   +-- fr
         +-- apac
         |   +-- ko
         |   +-- zh-cn
         
        If respectContent is true, then the resources ancestors (including the given one) are searched for a IS_LANGUAGE_ROOT_PROP_NAME property. If the property is true, ISO_PROP_NAME is used to determine language root. If the IS_LANGUAGE_ROOT_PROP_NAME property is false or the ISO_PROP_NAME property is not found or respectContent is false, the path of the resource is analyzed to find a matching iso code. Implementation may choose to optimize for certain type of hierarchies.
        Parameters:
        resolver - a ResourceResolver used to access the repository
        path - the path of the current page
        respectContent - if false only the path is analyzed
        Returns:
        a collection of language root resources
        Since:
        6.4
      • compareLanguageTrees

        LanguageManager.Tree compareLanguageTrees​(ResourceResolver resolver,
                                                  java.lang.String path)
        Compares language trees using the language of the page at the given path as main language.
        Parameters:
        resolver - resource resolved
        path - path to resource to start from
        Returns:
        the tree information