How to make template language independent

From The Document Foundation Wiki
Jump to: navigation, search

How to make template language independent

Description of the problem

When you create a template (for Impress for example), many informations are stored in your file. If you want to share it in an international environment (propose it to template site for instance), you need to remove all information about your localization (language, money unit, date format...). Otherwise, user need to modify language of many styles in each master page. If template was created by a German speaking user, orthography checking will be done in German.

This how-to explains how to remove all these informations (plus some extras), so that a new user opening this template will have orthography checking in his own language, whatever the language of the template's creator.

Prepare your template

Edit your template in Impress:

  • Remove all written text, such as "Write your text here"
  • Let only empty layout boxes
  • Remove date, footer text
  • Remove unused styles; user defined styles won't be translated. Refrain from using them and prefer predefined styles
  • Remove text in Notes also
  • Save it as template

Choose your preview image

In the template manager, a preview of the template is visible. You may want a clean preview, without reference to any language:

  • Open the template to create a new presentation
  • Choose the slide you want to see in the preview
if you have several slides in your template, move to first position the slide you want to see in preview
  • Insert "Lorem Ipsum" text in title and text to have an overview of the font used in your template. "Lorem Ipsum" text may be generated in Writer, thanks to an autotext: hit lorem+F3
  • Save your presentation as standard ODP file. Let's name it example.odp.

Modify XML code

XML code

Templates have file extension as .OT?, with ? standing for:

  • T = .OTT template for Writer
  • S = .OTS template for Calc
  • P = .OTP template for Impress
  • G = .OTG template for Draw

See What is the file format used by LibreOffice? question to have more details, but in a nutshell, these files formats are simply zipped archive containing a structure with XML files (See LibreOffice and XML). So to access XML code, you need first to unzip OT? file. Use your favorite archive software to unzip. You may need to rename file extension to .ZIP or not depending of your software.

Content and modification of a template file

For an Impress template you will get a structure like this:

  • Configurations2 directory should be removed. It may be empty or contain modifications of the configuration in menu bars or short keys. User may prefer to keep his own configuration when using your template
  • META-INF directory contains only one file manifest.xml. This file contains the list of files in the template. Edit it and remove any reference to Configurations2 if you removed it.
  • Pictures directory contains all images used in the template. Check if you really need all these images. If you remove some, update manifest.xml.
  • Thumbnails directory contains preview image. We will update it later.
  • content.xml file should not need to be modified if you correctly clean your template in Impress. You may check if there is no text.
  • meta.xml file contains general information of file: date of creation, authors, version used to build it... Nothing to change here.
  • mimetype is a text file describing the type of the file. It should contains:
It is useful for OS detecting type of the file

The main part of cleaning is to be done in the two following files. If your file has a long history, you may find many useless things.

  • settings.xml file contains the settings of many option you used when you created the template. However, many of these settings are useless for the user, or the user may prefer different options (printer settings, grid and snap options...). Check all options if you want to impose some. Otherwise you may safely remove the file (update manifest.xml) to let user uses its own settings.
  • styles.xml file contains all styles used in the template. Search and remove language and country tags:
    • fo:language="xx"
    • fo:country="XX"
    • style:language-asian="xx"
    • style:country-asian="XX"
    • style:language-complex="xx"
    • style:country-complex="XX"

Change preview picture

  • Unzip example.odp
  • Copy thumbnail.png file in Thumbnails directory
  • Paste it in the directory of the template to replace it

Build template file

Simply zipping all directories and files of the template in a zip file will create a template that LibreOffice will be able to open. However this file would not be valid as mimetype file will be zipped and randomly placed in the file. To get a valid OpenDocument file, you need to place it at the beginning of the file without compression.

Under Windows

To obtain such file, you may read How to of Regina Henschel.

Under Linux

Unzip is simply done from file manager: right clic on file  ▸ Extract here.

To re-zip, you can use following commands in console in the directory containing mimetype file:

zip -0 -X ../template2.otp mimetype
zip -r ../template2.otp * -x mimetype

First line creates a new zip file, with only mimetype file, without compression. Second line adds all other files recursively, except mimetype file, with standard compression

Test your template

Your template is now ready to be tested before diffusion. Make sure it is valid against ODF 1.2.extended, as far as possible. Validator is