EXT Resources Library - lang

The res::lang functor finds a resource language identifier for a resource. When more language versions of the same resource are available, it returns the closest one to the chosen language.


Interface:

When initializing the res::lang object, you may provide a handle to the module containing the resources. If no parameter is provided, the process executable is assumed.

The res::lang class provide following interface:

class res::lang {
    public:
        const void * const hInstance;
    public:
        lang (const void * = NULL);

        template <typename TYPE_T, typename NAME_T>
        unsigned short int operator ()
            (TYPE_T, NAME_T, unsigned char = 0, unsigned char = 0) const;
};

To find a resource language identifier of a resource, invoke the .operator () () and provide the resource type, name and prefered language (type and subtype, which defaults to LANG_NEUTRAL and SUBLANG_DEFAULT). The operator returns the best language identifier found for the resource or throws the ext::object_not_exists exception if no such resource exists.

The lookup algorithm searches for resources in this order:

  1. The specified language and sub-language
  2. The specified language and neutral (SUBLANG_NEUTRAL) sub-language
  3. The specified language and default (SUBLANG_DEFAULT) sub-language
  4. The specified language and first available sub-language
  5. The user default language and sub-language
  6. The user default language and neutral sub-language
  7. The user default language and default sub-language
  8. The user default language and first available sub-language
  9. The system default language and sub-language
  10. The system default language and neutral sub-language
  11. The system default language and default sub-language
  12. The system default language and first available sub-language
  13. The neutral language (LANG_NEUTRAL) and neutral sub-language
  14. The neutral language and default sub-language
  15. The english language (LANG_ENGLISH) and neutral sub-language
  16. The english language and default sub-language
  17. The english language and first available sub-language
  18. The first language found and neutral sub-language
  19. The first language found and default sub-language
  20. The first language found and first available sub-language

There are following exceptions to this order:

  1. If no sub-language identifier is provided the lookup starts at step 2.
  2. If no language and sub-language identifiers are provided or LANG_NEUTRAL and SUBLANG_DEFAULT are specified, the lookup starts at step 5.
  3. If LANG_NEUTRAL and SUBLANG_SYS_DEFAULT identifiers are provided, the lookup starts at step 9.

You will need to include "ext/res_bits/lang.cpp" into your project in order to use res::lang.

Examples:

#include <windows.h>
#include <ext/res>

int main () {
    std::printf ("%u\n", res::lang () (RT_STRING, 2, LANG_CZECH));

    return 0;
};

Remarks

Note that the win::lang is currently broken in way that use of RT_XXX constants will not compile if UNICODE is also defined.


[index]