Localization of system status messages

I work in a .NET environment where the system sometimes generates log entries for the client. Messages are then added to the client’s log, which can be viewed later.

For example, if a customer subscribes to a new service or the customer has a failed payment attempt, these messages are added to the customer’s journal.

Currently, all messages are hardcoded in the code, for example, "The client could not complete payment XX."

The problem is that these messages should be localized in a reasonable way, so that when an English user views the client’s log, he receives messages in English, and when a foreign user views the log, he receives them in his language.

What would be the best way to handle this scenario?

+4
source share
2 answers
  • Log event IDs, not messages.
  • Capturing data associated with a specific event, together with the event identifier.
  • When a user views the log, localize the event message based on a unique identifier.

The problem that you will encounter is that you are trying to insert dynamic data into messages in an interactive way. For example, if you need to write “No messages found” against “One message found” against “X messages found” is problematic - in English we have different values ​​for zero, one or more than one ... but this is not necessarily the same as in other languages. Things like numbers or dates are less problematic to insert into a String.Format form, but you do not want you to try to dynamically generate a real language locally.

I would recommend the following template, similar to the Windows event log, in which you displayed the event identifier, a localized message based on the event identifier and then fixed certain "fields" in which you localize the field name and the displayed field format, for example, "Amount: $ 2.00" or something else. Perhaps this is not the most beautiful way, but if you do not have a full-fledged linguist dedicated to this, and you intend to take into account all the subtle nuances in each language, I would post it and go with a simpler output format for the magazine.

In this example, you must separate the log message from the data, for example:

Customer did not complete payment.
Amount: XX

You would register a message identifier, for example, "13579" may be a unique identifier for the event when the customer does not complete the payment. Finally, you can save this value as a separate field.

How do you know how many fields to highlight an event or how to store data ... well, the exercise is best left to the reader.

+4
source

You can define localized rows in your database and simply register the log message identifier in the log table. The log message table also contains a field for specifying the language.

If you do a lot of logging, this will also reduce the size of your log (although this is probably not relevant given the storage space available on modern computers;)

This method has two problems:

  1. You need to synchronize the logging in your application with the log message table.
  2. You cannot register dynamic data, for example. customer name.

The first point can be resolved using an enumeration with descriptive names, for example

enum LogMessages { OutOfDiskSpace = 1; OutOfMemory = 2; OutOfCoffee = 3; } 

In your application, you would call void LogToDatabase(LogMessages) as follows:

 // forgot to buy coffee again! Log(OutOfCoffee); 

The second problem requires additional work. You can define your strings so that you can use string.Format() :

  string.format("{0} forgot to buy coffee again. Lazy geek!", "I"); // yields: "I forgot to buy coffee again. Lazy geek!" 

To do this, you need to save the variation data ("I", "you", "My little brother" ...) in the log table along with the log message identifier. (Or you normalize it a little more and put it in the third table, but this may well be premature normalization ;-).

+1
source

All Articles