3.15.  Language

Overview

PDF documents can be read out by screen readers for visually handicapped users. These programs need documents with a given country or language code.

The language of a PDF document can easily be checked using the following tag:

<!-- Tag to verify locale: -->

<hasLocale name=".."           (optional)
           string=".."         (optional)
           expectedEmpty=".."  (optional)
/>

<hasNoLocale />

Examples

<testcase name="hasLocale_CaseInsensitive_LowerCase">
  <assertThat testDocument="language/_languageInfo/localeDemo_en-GB.pdf">
    <hasLocale string="en-gb" />  1
  </assertThat>
</testcase>
<testcase name="hasLocale_CaseInsensitive_UpperCase">
  <assertThat testDocument="language/_languageInfo/localeDemo_en-GB.pdf">
    <hasLocale string="en_GB" />  1
  </assertThat>
</testcase>

1

Notation typical for PDF

1

Notation typical for Java

The string for the language is not case sensitive. Underscore and hyphen are equivalent.

You can also use a value of java.util.Locale. But that is case sensitivity:

<testcase name="hasLocale_LocaleInstance_GERMANY">
  <assertThat testDocument="language/_languageInfo/localeDemo_de.pdf">
    <hasLocale name="Locale.GERMANY" />
  </assertThat>
</testcase>
<testcase name="hasLocale_LocaleInstance_GERMAN">
  <assertThat testDocument="language/_languageInfo/localeDemo_de.pdf">
    <hasLocale name="Locale.GERMAN" />
  </assertThat>
</testcase>

A PDF document with the locale "en_GB" is tested successfully when using the locale Locale.en. In the opposite case, a document with the locale "en" fails when it is tested against the expected locale Locale.UK.

You can also check that a PDF document does not have a country code:

<testcase name="hasLocale_LanguageEmpty">
  <assertThat testDocument="language/_languageInfo/localeDemo_null.pdf">
    <hasNoLocale />
  </assertThat>
</testcase>