Visit Mozilla.org

nsIStringBundle

From MDC


The nsIStringBundle interface provides functions for retrieving both formatted and unformatted strings from a properties file. This interface is used by XUL:stringbundle to retrieve strings. It is recommended that you use the methods of XUL:stringbundle to access these functions unless necessary.

Contents

nsIStringBundle is defined in intl/strres/public/nsIStringBundle.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.0).

Inherits from: nsISupports

[edit] Method overview

wstring GetStringFromID(in long aID);
wstring GetStringFromName(in wstring aName);
wstring formatStringFromID(in long aID, [array, size_is(length)] in wstring params, in unsigned long length);
wstring formatStringFromName(in wstring aName,[array, size_is(length)] in wstring params, in unsigned long length);
nsISimpleEnumerator getSimpleEnumeration();

[edit] Methods

[edit] GetStringFromID()

Retrieves a string from the bundle by its ID.

 wstring GetStringFromID(long aID);
[edit] Parameters
aID
The ID of the string to retrieve. String ID's are assigned by the order in which they are stored in the properties file.
[edit] Return value

Returns the requested string.

[edit] GetStringFromName()

Retrieves a string from the bundle by its name.

 wstring GetStringFromName(wstring aName);
[edit] Parameters
aName
The name of the string to retrieve. String name are designated in the properties file.
[edit] Return value

Returns the requested string.

[edit] formatStringFromID()

Returns a formatted string with the given ID from the string bundle, where each occurrence of %S (uppercase) is replaced by each successive element in the supplied array. You may also use other formatting codes. You can only pass Unicode strings in. The ID should refer to a string in the bundle that uses %S. Do NOT try to use any other types. This uses nsTextFormatter::smprintf.

 wstring formatStringFromID(long aID,
                            [array, size_is(length)] wstring params,
                            unsigned long length);
[edit] Parameters
aID
The ID of the string to retrieve.
params
Parameters to pass in to the string.
length
The length of the parameter list.
[edit] Return value

Returns the formatted string.

[edit] formatStringFromName()

Returns a formatted string with the given key name from the string bundle, where each occurrence of %S (uppercase) is replaced by each successive element in the supplied array. You may also use other formatting codes, but can only pass Unicode strings in. The name should refer to a string in the bundle that uses %S. Do NOT try to use any other types. this uses nsTextFormatter::smprintf to do the dirty work.

 wstring formatStringFromName(in wstring aName,
                            [array, size_is(length)] wstring params,
                            unsigned long length);
[edit] Parameters
aName
The name of the string to retrieve.
params
Parameters to pass in to the string.
length
The length of the parameter list.
[edit] Return value

Returns the formatted string.


[edit] getSimpleEnumeration()

 nsISimpleEnumerator getSimpleEnumeration();
[edit] Return value

Returns an nsISimpleEnumerator which iterates over all the strings in the bundle.

[edit] See also