Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Development  >  internationalization
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.

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 bool ContainsKey(string key)

GetMessage() member function

The signature of the GetMessage() member function 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() member function

The signature of the AddMessage() member function 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() member function

The signature of the SetMessage() member function 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() member function

The signature of the SetFromFile() member function 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 at once.

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.

ContainsKey() member function

The signature of the ContainsKey() member function 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.

Previous
Copyright © Rice All rights reserved.