DEV Community

Peter + AI
Peter + AI

Posted on

🌍 Uniface Localization Series (Part 2): The Secret Sauce - Message Libraries πŸ“š

Welcome back! In Part 1, we looked at the architecture of our Date/Time localization sample. Now, let's get our hands dirty and see how Uniface actually knows that Germany uses DD.MM.YYYY and the US uses MM/DD/YYYY.

The secret lies in the Uniface Message Library. 🀫


πŸ“¦ The Container: libmsg_locale_datetime.xml

In the sample files, you'll find libmsg_locale_datetime.xml. This isn't just a random XML file; it's an export of a Uniface Message Library.

In Uniface, libraries are used to store reusable components, global variables, andβ€”crucially for usβ€”Messages and Formats.

🚫 The Bad Way (Hardcoding)

Instead of hardcoding formats in your ProcScript like this (don't do this!):

if ($language = "DE")
   date_field = "DD.MM.YYYY"
endif
Enter fullscreen mode Exit fullscreen mode

βœ… The Good Way (Message Library)

The sample uses the Message Library to define Locale Definitions.

🧩 How it works

Inside the XML (and the Uniface IDE), you define specific message IDs that correspond to different locales.

For example, the sample likely defines messages that act as masks for input and output. When you switch the locale in the app, Uniface looks up the corresponding format in the library.

  • Locale en_US: Might point to a format message defined as MM/DD/YYYY HH:NN:SS.
  • Locale de_DE: Points to DD.MM.YYYY HH:NN:SS.
  • Locale nl_NL: Points to DD-MM-YYYY HH:NN:SS.

This abstraction is powerful because it keeps your business logic clean. Your code just says "Display the date," and the Library says "Here is how it looks in German." πŸ‡©πŸ‡ͺ✨

πŸ’» The DSP Logic

In the prj_full_locale_datetime.xml, we find the Dynamic Server Page (LOCALE_DATETIME).

When the user selects a new language from the dropdown, a trigger fires. This trigger updates the $variation or a similar locale setting in the runtime.

The beauty of the Uniface Web Runtime is that once this setting is updated, the framework automatically re-applies the formats defined in the library to all fields on the page. You don't have to manually loop through every field to re-format it! πŸ”„

πŸ’‘ Key Takeaway

Don't hardcode formats! Use the power of Uniface Libraries. It makes adding a new language (say, Japanese πŸ‡―πŸ‡΅) as simple as adding a new entry in the library, without touching your core application code.

In the next (and final) part, we'll wrap up with some best practices and how to verify your changes using the browser's developer tools! πŸ› οΈ

πŸ“₯ Source:

Original Sample:

Web sample: Date Time Localization by Peter Beugel

See you in Part 3! πŸ‘‹

Top comments (0)