Adding localization to pages

Okay, we've successfully added a few languages to our website and updated our template to handle the new languages, but you've probably noticed that nothing has really changed. In fact, if you go to one of our pages in the frontend and add&L=1 or&L=2 to the URL, the only change you can see is the date format. Everything is still in English, and it's not even hiding the non-translated content. That's okay, because it just means that we have not added translations to our individual pages, yet. The TypoScript we just added will hide non-translated content elements on a translated page, but the default TYPO3 response to a non-translated page is to show the default language. We can change that in a moment if we want to hide the default language for non-translated pages. For now, let's just translate our main page.

We add a language to pages in TYPO3 through an Alternative Page Language record, and it's easier than it sounds. By adding an Alternative Page Language record to any page in TYPO3, we are saying that we want to start showing an alternative version of our page to visitors using the Website Language record and we need to start seeing translation buttons in the backend Page and List views. This is set for each page as part of the developer's design, and it makes sense once you're used to it. In the real world of international websites, it is common to translate only parts of a site. Even the largest companies will often tailor which pages need to be seen in certain regions. This happens because some pages are not applicable to all areas, local working groups may manage some sections, and sometimes it's just not feasible to translate something like a company blog into multiple languages. TYPO3 gives us control over which pages and which content elements are available in each locale that we are targeting.

We can create an Alternative Page Language record for any page through the Page view by clicking on the Localization view tab that is now available. Just choose a language from the drop-down menu, and we're ready to create our record:

Adding localization to pages

Tip

Once we choose a language from the drop down, TYPO3 will create an Alternative Page Language record that we can also see in the List view. This can be helpful for debugging problems with translations if we think that the Alternative Page Language record has been accidentally deleted.

By choosing a new language from the drop down, we can start creating a new record and go to an editing screen like the one shown in the following screenshot. In that screen, we can set a translated title for our page. As TYPO3 uses our page titles for menu items, this will automatically translate our menu as well. We can also use this opportunity to translate keywords, description, or anything else that is stored in the page properties. We can even modify the access rules or available resources if we want. You can see an example of the Alternative Page Language record page when it is filled out below:

Adding localization to pages

Once we are happy with our changes, we can save our Alternative Page Language. If we reload the same page in the frontend with the URL variable L=1, then we will see that the content elements are now missing. We have set our website to hide the non-translated content elements, so we will need to translate the content elements before they become visible again.

Using the localization tab in the Page view

Now that we have added an alternative language to our current page, the Localization view tab in the Page module becomes a more important part for our workflow:

Using the localization tab in the Page view

The drop downs can be used to change the way we view the page for editing so that we can concentrate on editing the default language or translating content. Here is a list of the options that are available and how they affect our Page view:

  • Show page language version: Displays a list of the current languages available to work with.
  • Display mode: This can be set to Default, Selected language, or Only Localized Elements. If it is set to Selected language, any content elements that have been translated into the selected language are visible along with the default language versions. If it is set to Only localized elements, then the current language version of all translated content elements will be shown without the original default language versions. When we start translating content elements in a moment, this will make more sense.
  • Edit page properties: This shows flags for the alternative languages, and we can use these to access page properties such as titles and metadata for translated pages.
  • Create new page translation: We saw this just a minute ago as a quick way of creating a new Alternative Page Language record.

Hiding non-translated pages

You probably noticed that all of our pages are still available in the menu no matter what language we are in, and most of them aren't translated. TYPO3 allows hiding certain pages if they are not translated so that they will be accessible or appear in the menu, or we can change our configuration to hide all non-translated pages by default.

We can set individual pages to stay hidden if they don't have an Alternative Page Language record for the current language through the page properties. In the Options tab, we can set our localization settings to hide the non-translated page by checking the option labeled Hide page if no translation for current language exists.

If we only want our page to be available in a non-default language (if we only want the page in Irish, not English) we can hide the default translation of a page by checking the option labeled Hide default translation of page:

Hiding non-translated pages

If we want to change the default setting for our entire TYPO3 installation, we can change that as well. As this affects the entire TYPO3 installation, instead of just the page tree, we have to make our change in the TYPO3 configuration file instead of the TypoScript template. To hide all non-translated pages (pages without an Alternative Page Language record) by default, we can add the following line to our typo3conf/localconf.php file:

$TYPO3_CONF_VARS['FE']['hidePagesIfNotTranslatedByDefault'] = '1';

This only changes the default setting to hide pages. We can still choose to show pages without a translation through the page properties. If TYPO3 is set to hide non-translated pages by default, the option in page properties changes to read Show page even if no translation exists. You can still choose to show pages that may not need a native translation like image galleries or links to online stores that have their own translation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.29.195