E07157: what it makes for that language can never be set

Category: E07xxx Full resolution · Reported in phase: FULL_RESOLUTION · Classification: TEXT_LANGUAGE_NOT_DEFINED · All error codes

What went wrong

A text is made with a plain String literal naming a language that has no 'defines text for' block of that text. At run time the language is compared EXACTLY with each block's language; when none matches, what is made is an unset text whose messages all return unset Strings (and printing an unset String prints nothing). A literal is known when the program is compiled, so this one could never be set. There is no fallback from a region to its language: a text with only an "en_GB" block has no "en". The message lists the languages the text does have, from every file of the module.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 113 (How does the text construct work for internationalization?)

How to fix it

  1. If the text should speak that language, add a block for it, holding the same methods as the other blocks (every language must provide every method, E07150) - good_fix.ek9 in the [EXAMPLE] section below adds the missing block
  2. If the language is chosen at run time, compute it and give a fallback with '?:', or ask with '?' or a guard first - good.ek9 in the [EXAMPLE] section below falls back to "en" when the language it is given has no block
  3. If the literal is a typing mistake, use one of the languages listed in the message - for a region block write the region too, "en_GB"

Common causes

  • A language written before its 'defines text for' block was added
  • Asking for a language ("en") when only a region block ("en_GB") exists
  • A misspelt or wrong-case language ("EN", "fr_fr")
  • A literal used to try out a language the program will really compute

See also

  • E07150: text method missing for language variant
  • E07155: text type already defined for this locale
  • E07900: invalid value - a text language that is not a locale

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07157: what it makes for that language can never be set

#!ek9
defines module error.e07157.bad

  defines text for "en"

    Greetings
      hello()
        "Hello"

  defines text for "fr"

    Greetings
      hello()
        "Bonjour"

  defines program

    SayHello()
      stdout <- Stdout()

      //Greetings has text for "en" and "fr" only, so Greetings("de") is always unset
      greetings <- Greetings("de")
      stdout.println(greetings.hello())

Fixed: Give Greetings the "de" text it is asked for

#!ek9
defines module error.e07157.good.fix

  defines text for "en"

    Greetings
      hello()
        "Hello"

  defines text for "fr"

    Greetings
      hello()
        "Bonjour"

  defines text for "de"

    Greetings
      hello()
        "Hallo"

  defines program

    SayHello()
      stdout <- Stdout()

      greetings <- Greetings("de")
      stdout.println(greetings.hello())

Fixed: Choose the language at run time and fall back with '?:'

#!ek9
defines module error.e07157.good

  defines text for "en"

    Greetings
      hello()
        "Hello"

  defines text for "fr"

    Greetings
      hello()
        "Bonjour"

  defines function

    //A computed language may have no text: Greetings(language) is then unset, so fall back to "en".
    greetingsFor() as pure
      -> language as String
      <- rtn as Greetings: Greetings(language) ?: Greetings("en")

  defines program

    SayHello()
      stdout <- Stdout()

      greetings <- greetingsFor("de")
      stdout.println(greetings.hello())

Questions and answers

These Q&A entries show E07157 and its fix:

Found a problem?

If EK9 reported E07157 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.