CSDNCurrent en:Language Resources

Aus Cryptshare Documentation
Wechseln zu:Navigation, Suche



The Cryptshare Server can provide the Client with the language resources contained in the Language Packages that have been installed on the server. These Language Packages can then be used for a user interface on client side, for instance.

Available Languages

You can check what languages are available on the server using the Client's method RequestLanguagePacks(). It will return a list of LanguagePack objects containing information about each installed language pack. You can then use the data from this list to request a specific language pack file for download.

Example: Requesting a List of Available Languages

// First create the Client instance
// Create a WebServiceUri for your Cryptshare Server 
WebServiceUri serviceUri = new WebServiceUri("http://cryptshare.server.com");

// Create a CryptshareConnection instance for your WebServiceUri
CryptshareConnection connection = new CryptshareConnection(serviceUri);

// Create the Client instance with the sender's email address, 
// the CryptshareConnection, and the path to the verification store.
Client client = new Client("sender_email@server.com", connection, @"C:\temp");

// Now we can request the list of installed languages
List<LanguagePack> languagePackList = client.RequestLanguagePacks();

foreach (LanguagePack languagePack in languagePackList)
{
    System.Globalization.CultureInfo locale = languagePack.Language;
    String version = languagePack.Version;
    long lastUpdate = languagePack.LastUpdate;
    Console.WriteLine("Language pack language = " + locale.TwoLetterISOLanguageName +
        " with version = " + version + " last updated at " + lastUpdate);
}

Downloading a Language Pack File

Now that you know which Language Packages are available on the server, you can download a specific language pack file using the Client's method RequestLanguagePackFile(String,CultureInfo). The method requires the base name of the actual language pack file on the server as the first parameter and the desired Locale as the second parameter.

Language Pack Base Name
The base name of the actual language pack file on the server is just the file name, minus the language or country information. For example, if you have the language pack file "lang_en_GB.xml" installed on the server, the base name for that language pack file would be "lang.xml". So you would request this particular language pack file, using the following method call:

CultureInfo culture = CultureInfo.CreateSpecificCulture("en-GB");

byte[] langFileBytes = client.RequestLanguagePackFile("lang.xml", culture);

Here is a complete example of how to request a specific language pack file:

Example: Downloading a Language Pack File

// First create the Client instance
// Create a WebServiceUri for your Cryptshare Server 
WebServiceUri serviceUri = new WebServiceUri(ServerUrl);

// Create a CryptshareConnection instance for your WebServiceUri
CryptshareConnection connection = new CryptshareConnection(serviceUri);

// Create the Client instance with the sender's e-mail address, 
// the CryptshareConnection, and the path to the verification store.
Client client = new Client("sender_email@server.com", connection, @"C:\temp");

// Get the list of available languages
List<LanguagePack> languagePackList = client.RequestLanguagePacks();

// Now we can request the download of a specific language pack file, where
// the first parameter of the method is the base name of the physical language 
// pack file on the server, and the second parameter is the desired Culture.
// For this example, we will just download the first language pack from the
// list of available languages.
byte[] langFileBytes = client.RequestLanguagePackFile("lang.xml",
    languagePackList[0].Language);

// save the file to the current directory on our local disk 
if (langFileBytes != null)
{
    FileStream fs = null;
    try
    {
        fs = File.Create(@"C:\temp\lang.xml");
        fs.Write(langFileBytes, 0, langFileBytes.Length);
        fs.Close();
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }
    finally
    {
        try
        {
            fs.Close();
        }
        catch (Exception)
        {
        }
    }
}