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
β 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 asMM/DD/YYYY HH:NN:SS. - Locale
de_DE: Points toDD.MM.YYYY HH:NN:SS. - Locale
nl_NL: Points toDD-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)