Internationalization

Message

If there is an error in the program, an exception is thrown. Exceptions thrown include messages that are hints on errors that occurred.

Rice's default message is English, but if the messages are your native language, you should be able to understand the cause of the error sooner.


Rice has been provided an interface for changing messages.

By using this interface, you can change messages to any language.

If you implement a new embedded class, messages for that class may be needed, but you can easily add new messages.

Message specification

The Rice message is a pair of a message name and a message body.

For example,


interpreter_dummy > "Right-hand side is undefined."


Within Rice, the message is managed as an associative array whose message name is the key and message body is the value.

Before Ver 1.3.1.0 used a minus sign in the message name, but in Ver 1.3.1.0 the minus sign in the message name has been changed to an underscore.

interpreter-dummy > interpreter_dummy

Interface for message management

The following static member functions of RiceManager class (C #) are interface for message management.


public static string GetMessage(string key)

public static string AddMessage(string key, string value)

public static string SetMessage(string key, string value)

public static void SetFromFile(string fileName)

public static void SetFromResource(ResourceManager manager)

public static void SetFromResource(ResourceManager manager, CultureInfo info)

public static bool ContainsKey(string key)

The following functions have been added in Ver 1.3.1.0.

public static void SetFromResource(ResourceManager manager)

public static void SetFromResource(ResourceManager manager, CultureInfo info)

GetMessage(string) member function

The signature is shown below.


public static string GetMessage(string key)


This member function accepts the message name as an argument and returns the corresponding message body.

If the key(message name) do not exist, this method throw the KeyNotFoundException.

AddMessage(string,string) member function

The signature is shown below.


public static string AddMessage(string key, string value)


This member function accepts the message name (key) and message body (value) as arguments and returns the message body.

If the message name does not exist, it registers the message name and body pair and returns the registered body.

If the message name already exists, it does not register the new body. And, it returns the old body which has already been registered.

In other words, the message body is not overwritten.

SetMessage(string,string) member function

The signature is shown below.


public static string SetMessage(string key, string value)


This member function accepts the message name (key) and message body (value) as arguments and returns the message body.

If the message name does not exist, it registers the message name and body pair and returns the registered body.

Even if the message name already exists, it registers a new body and returns the newly registered body.

In other words, the message body is overwritten.

SetFromFile(string) member function

The signature is shown below.


public static void SetFromFile(string fileName)


This member function accepts the path to the text file as an argument and changes the messages.

If the message name does not exist, it registers a message name and body pair.

Even if the message name already exists, it registers a new body.

In other words, the message body is overwritten.


This member function does nothing if the file does not exist in the specified path.

The file format required for message registration will be described later.

SetFromResource(ResourceManager) member function

The signature is shown below.


public static void SetFromResource(ResourceManager manager)


This member function changes messages using System.Resources.ResourceManager and the current culture.

Use the resource name as the message name. The message body is the value of the corresponding resource. Resources other than strings are ignored.

If the message name does not exist, it registers a message name and body pair.

Even if the message name already exists, it registers a new body.

In other words, the message body is overwritten.

Added in Ver 1.3.1.0.

SetFromResource(ResourceManager,CultureInfo) member function

The signature is shown below.


public static void SetFromResource(ResourceManager manager, CultureInfo info)


This member function changes messages using System.Resources.ResourceManager and System.Globalization.CultureInfo.

If there is no corresponding culture for the argument, the default culture will be used.

Use the resource name as the message name. The message body is the value of the corresponding resource. Resources other than strings are ignored.

If the message name does not exist, it registers a message name and body pair.

Even if the message name already exists, it registers a new body.

In other words, the message body is overwritten.

Added in Ver 1.3.1.0.

ContainsKey(string) member function

The signature is shown below.


public static bool ContainsKey(string key)


This member function returns whether the message name (key) has already been registered.

It returns true if the message name has already been registered.

It returns false if the message name is not registered.

Message file specification

When using the SetFromFile() member function, the file used for the change must conform to a certain format.


First, the file must be a UTF-8 encoded text file.


A line beginning with # in the file is comment line. it is ignored when registering messages.

A line which does not begin with # indicates a pair of message name and body. Message names and body will be separated by ::: (triple colon).

In the string delimited by :::, the first is the message name, and the second is the message body to be registered.


There is no restriction on the characters and length used for the message name and body. However, since ::: is a separator, it can not be used.


There is no problem even if there are two or more strings delimited by :::. Third and later are ignored.

In the message.txt of the download package, the English original message have been written as the third string.

Please see message.txt for details.

Copyright © Rice All rights reserved.