Namespace Lucene.Net.QueryParsers.Flexible.Messages
For Native Language Support (NLS), system of software internationalization.
NLS message API
This utility API, adds support for NLS messages in the apache code. It is currently used by the lucene "New Flexible Query PArser".
Features:
- Message reference in the code, using static Strings
- Message resource validation at class load time, for easier debugging
- Allows for message IDs to be re-factored using code re-factor tools
- Allows for reference count on messages, just like code
- Lazy loading of Message Strings
- Normal loading Message Strings
Prerequisite for these examples: Add a resource file named MessagesTestBundle.resx
and add messages for each of the public static string fields except for Q0005E_Message_Not_In_Bundle
.
Lazy loading of Message Strings
public class MessagesTest : NLS
{
private static readonly string BundleName = typeof(MessagesTest).FullName;
private MessagesTest()
{
// should never be instantiated
}
static MessagesTest()
{
InitializeMessages(BundleName, typeof(MessagesTest));
}
// static string must match the strings in the property files.
public static string Q0001E_Invalid_Syntax;
public static string Q0004E_Invalid_Syntax_Escape_Unicode_Truncation;
// this message is missing from the properties file
public static string Q0005E_Message_Not_In_Bundle;
}
// Create a message reference
IMessage invalidSyntax = new Message(MessagesTest.Q0001E_Invalid_Syntax, "XXX");
// Do other stuff in the code...
// when is time to display the message to the user or log the message on a file
// the message is loaded from the correct bundle
string message1 = invalidSyntax.GetLocalizedMessage();
string message2 = invalidSyntax.GetLocalizedMessage(new CultureInfo("ja"));
Normal loading of Message Strings
string message1 = NLS.GetLocalizedMessage(MessagesTest.Q0004E_Invalid_Syntax_Escape_Unicode_Truncation);
string message2 = NLS.GetLocalizedMessage(MessagesTest.Q0004E_Invalid_Syntax_Escape_Unicode_Truncation, new CultureInfo("ja"));
The Lucene.Net.QueryParsers.Flexible.Messages.TestNLS
NUnit test contains several other examples. The TestNLS C# code is available from the Apache Lucene.NET code repository.
Classes
Message
Default implementation of Message interface. For Native Language Support (NLS), system of software internationalization.
NLS
MessageBundles classes extend this class, to implement a bundle.
For Native Language Support (NLS), system of software internationalization.
This interface is similar to the NLS class in eclipse.osgi.util.NLS class - initializeMessages() method resets the values of all static strings, should only be called by classes that extend from NLS (see TestMessages.java for reference) - performs validation of all message in a bundle, at class load time - performs per message validation at runtime - see NLSTest.java for usage reference
MessageBundle classes may subclass this type.
Interfaces
IMessage
Message Interface for a lazy loading. For Native Language Support (NLS), system of software internationalization.
INLSException
Interface that exceptions should implement to support lazy loading of messages.
For Native Language Support (NLS), system of software internationalization.
This Interface should be implemented by all exceptions that require translation