The most common use cases are described in the sections below.
Clients can use the S60 specified default localization data, or define a new one in a resource file. An example Directory Localizer containing two directory resources is shown as below:
#include "DirectoryLocalizer.rh" RESOURCE DIRECTORYLOCALIZER r_example_localizer_entries { directories = { DIRECTORY { fullPath = “c:\\example\\”; localizedName = “Example”; extraData = “New localizer”; iconIndex = 0; }, DIRECTORY { fullPath = “c:\\example2\\”; localizedName = “Example2”; extraData = “New localizer 2”; iconIndex = 0; } }; }
Directory Localizer may be initialized with the default localizer resource, or a client specified resource. The following code snippet demonstrates how to initialize a localizer with the resource defined in the above section.
// Assumption: the localizer resource is defined in resource file “example.rss”. // #include <example.rsg> _LIT(KDLExampleResourceFile, "z:\\resource\\example.rsc" ); // Load the resource file to the environment. // TInt offsetRscFile = CCoeEnv::Static()-> AddResourceFileL(KDLExampleResourceFile); // Initialize the localizer with the resource. // CDirectoryLocalizer* localizer = NULL; localizer = CDirectoryLocalizer::NewL( R_EXAMPLE_LOCALIZER_ENTRIES ); // Handle the localized data. ... // Delete the instance. // delete localizer; localizer = NULL; // Delete the resource file from the envionment. // CCoeEnv::Static()->DeleteResourceFile(offsetRscFile);
The following code snippet demonstrates how to add specified localizer
resource to the default localizer resource entries. In this case, a localizer
is initialized with the default localizer entries firstly, and then calling CDirectoryLocalizer::AddFromResourceL()
method
adds the resource defined in the above section.
// Assumption: the localizer resource is defined in resource file “example.rss”. // #include <example.rsg> _LIT(KDLExampleResourceFile, "z:\\resource\\example.rsc" ); // Load the resource file to the environment. // TInt offsetRscFile = CCoeEnv::Static()-> AddResourceFileL(KDLExampleResourceFile); // Initialize the localizer with the default resource. // CDirectoryLocalizer* localizer = NULL; localizer = CDirectoryLocalizer::NewL(); // Add resource entries. // localizer->AddFromResourceL(R_EXAMPLE_LOCALIZER_ENTRIES); // Handle the localized data. ... // Delete the instance. // delete localizer; localizer = NULL; // Delete the resource file from the envionment. // CCoeEnv::Static()->DeleteResourceFile(offsetRscFile);
The most important use case is to analyze an absolute path and retrieve
the localized attributes, e.g. the localized name. The following code snippet
demonstrates how to retrieve the localized attributes of the path defined
in KTestDir
.
// Assumption: CDirectoryLocalizer* localizer has been initialized as described // in the section “Initializing the directory localizer”. // // Define the input path. // _LIT( KTestDir, "c:\\example\\" ); // Set the absolute path to be localized. // localizer ->SetFullPath(KTestDir); if ( localizer->IsLocalized() ) { // The path is recognized as a localized directory. // Get the localized name. It should be “Example” // If the input path is not localized, the return value is KNullDesC. // TPtrC localizeName = localizer-> LocalizedName(); // Get the extra data. It should be “New localizer” // If the input path is not localized, the return value is KNullDesC. // TPtrC extraData = localizer-> ExtraData (); // Get the icon index. It should be 0. // If the input path is not localized, the return value is KErrGeneral. // TInt iconIndex = localizer-> Icon (); }
The path to be localized is defined with or without the trailing backslash depending on how the paths are defined in the directory resource. And the default localizer entries are defined with the trailing backslash. So it is recommended to define the path with the trailing backslash as the resource defined in section Defining the directory localizer in a resource file.
Some methods may leave, for example if running out of memory. Normal Symbian
OS error handling practices should be used, including e.g. using cleanup stack
and TRAP
harness.