1

Imagine I have the following predicate, which states that the ID loc1 designates a location.

isLocation('loc1', 'Location 1').

I want to provide translations for the second text (Location 1), i. e. key-value pairs such as en='Location 1', de='Ort 1', ru='Местоположение 1'.

What is the correct way to encode such data in Prolog, especially TuProlog (and ideally - standardized Prolog) ?

Would the notation below work outside SWI Prolog?

isLocation('loc1', ['en'-'Location 1', 'de'-'Ort 1', 'ru'-'Местоположение 1']]).
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • 5
    There is no need to use single quotes if the atom is also a valid atom without the quotes. Simply write such atoms down. as in `loc1`, `in`, `de` etc. Use GNU Prolog to see if your text is valid ISO syntax. SWI-Prolog is not ISO conformant and is not suitable for judging the validity of your Prolog syntax. – mat Feb 15 '16 at 08:03

1 Answers1

3

the easiest way, working in any Prolog, uses member/2 to retrieve key-value pairs. For instance

l10n(MessageId, Country, Translated) :-
  isLocation(MessageId, Localized),
  member(Country-Translated, Localized).

Such basic construct would need of course several improvements, depending on requirements.

CapelliC
  • 59,646
  • 5
  • 47
  • 90