An add-in contains several types of string which you might consider localizing, so that they appear in the language of the user.
In general, the technique for localizing strings in XLL+ is as follows:
Resource IDs are made up of prefixed integers (either decimal or hexadecimal), and can be in one of the following forms:
Type | Examples | Translation |
---|---|---|
Regional settings | #123 #0x7B |
Will be replaced by a string in the language implied by the user's current regional settings, if it can be found in the resource file. If the language cannot be found, then English will be used. The function used to detect the current language is XllGetStringLanguageID. |
Excel version | #@123 #@0x7B |
Will be replaced by a string in the language implied by the Excel version, if it can be found in the resource file. If the language cannot be found, then language implied by the user's current regional settings will be used. If that language cannot be found, English will be used. The function used to detect the Excel version language is XllGetExcelLanguageID. |
You can use a resource ID instead of a string in the following places:
In the XLL+ Function Wizard.
For instance, in the picture above, the resource id "#202" is used for the function's description. This will be replaced at run-time by a string from the resource file.
In source code, when calling some XLL+ functions.
m_menu.AddItem("#101", "MyFunction");
In the example above, the menu item's caption will be looked up in the resource file. It will be replaced with the best language match for string resource 101, according to the current language settings.
See ::XllTranslateString() for a list of all the XLL+ functions that accept and translate resource ID strings.
With ::XllTranslateString()
CString strOut; ::XllTranslateString("#ERROR: #102", strOut);
You can use ::XllTranslateString() to replace numeric string identifiers with appropriate language strings at run-time. This is the method used by the functions of the XLL+ run-time library.