Getting Started

In earlier versions, all string values (titles, messages, etc.) visible to the user were localized via special resource files (Resources.resx). Xafari Localizer is a new and more rational way to create and maintain localizations. This section demonstrates how to establish a localization based on the most recent approach. The sample application for this example is the Feature Center demo installed with the Xafari platform.

First, create the Localization folder and add the FeatureCenterLocalizer.cs file into it. See the code of the FeatureCenterLocalizer class below:

 

  • c#
  • VB

using Xafari.Localization;
namespace Xafari.FeatureCenter.Localization
{
  public class FeatureCenterLocalizer : XafariResourceLocalizer<FeatureCenterLocalizer, FeatureCenterItemsStringId>
  {
    public override string ResourceName
    {
      get
      {
        return "Xafari.FeatureCenter.Localization.Resources.FeatureCenterResources";
      }
    }
  }
}

Imports Xafari.Localization
Namespace Xafari.FeatureCenter.Localization
  Public Class FeatureCenterLocalizer
    Inherits XafariResourceLocalizer(Of FeatureCenterLocalizer, FeatureCenterItemsStringId)
    Public Overrides ReadOnly Property ResourceName As String
      Get
        Return "Xafari.FeatureCenter.Localization.Resources.FeatureCenterResources"
      End Get
    End Property
  End Class
End Namespace

Then, add the FeatureCenterItemsStringId.cs into the Localization folder. The file should include all constants from the Properties.resx (or Resources.resx) file:

  • c#
  • VB

public enum FeatureCenterItemsStringId
{
  Error,
  Info,
  ManagedOperationsASyncError,
  ManagedOperationsASyncGlobalProcess,
  ManagedOperationsASyncProcessException,
  ManagedOperationsASyncSubprocess,
  ManagedOperationsASyncSubprocessException,
  ManagedOperationsASyncUniqueProcess,
  ManagedOperationsSubprocesses,
  ManagedOperationsSyncMO,
  ManagedOperationsSyncMOEmpty,
  ManagedOperationsSyncMOMarquee,
  ManagedOperationsSyncMOProgress,
  ManagedOperationsSyncMOSubException,
  ManagedOperationsSyncMOSubprocesses,
  Note,
  ProcessWithProgress,
  ProcessWithSubprocesses,
  SimpleAction,
  Stage,
  Subprocess,
  Success,
  UniqueProcessWithSubprocesses,
  UsedDate,
  Warning
}

Public Enum FeatureCenterItemsStringId
  [Error]
  Info
  ManagedOperationsASyncError
  ManagedOperationsASyncGlobalProcess
  ManagedOperationsASyncProcessException
  ManagedOperationsASyncSubprocess
  ManagedOperationsASyncSubprocessException
  ManagedOperationsASyncUniqueProcess
  ManagedOperationsSubprocesses
  ManagedOperationsSyncMO
  ManagedOperationsSyncMOEmpty
  ManagedOperationsSyncMOMarquee
  ManagedOperationsSyncMOProgress
  ManagedOperationsSyncMOSubException
  ManagedOperationsSyncMOSubprocesses
  Note
  ProcessWithProgress
  ProcessWithSubprocesses
  SimpleAction
  Stage
  Subprocess
  Success
  UniqueProcessWithSubprocesses
  UsedDate
  Warning
End Enum

Copy (or create) the Resources.resx files (or a single one) from the Properties folder and rename them into FeatureCenterResources.resx. This should be done because we used this file name in the FeatureCenterLocalizer class for the ResourceName property. Register the created Localizer in the module as shown in the code sample below:

  • c#
  • c#(original)

public sealed partial class FeatureCenterModule : XafariModuleBase, ITypesProvider<IBusinessOperation>, ITypesProvider<IOperationService>
{
}

public sealed partial class FeatureCenterModule : XafariModuleBase, ITypesProvider<IBusinessOperation>,ITypesProvider<IOperationService>
 {
 . . . . . .
         public override ICollection<Type> GetXafResourceLocalizerTypes()
         {
             return new[] { typeof(FeatureCenterLocalizer)};
         }

 }

Finally, search the code for all places utilizing string values and change the method used to get them. In earlier versions, the following method was used:

  • c#
  • c#(original)

public override string SomeMethod {get;set;}

public override string SomeMethod
 {
 . . . . .
 Name = Resources.ProcessWithProgress
 }

All such samples should be replaced with the code below:

  • c#
  • c#(original)

public override string SomeMethod {get;set;}

public override string SomeMethod
 {
 . . . . .
 Name = FeatureCenterLocalizer.Active.GetLocalizedString(FeatureCenterItemsStringId.ProcessWithProgress)
 }

To check if everything was done correctly, launch the application and switch to the desired language by opening the Tools tab and choosing its Change Language menu item.

Now it is possible to modify localized values right in the Model Editor, as well as to add and customize localization both in run-time and design-time. To enable these opportunities, open the Application Designer, navigate to Properties, and click the button situated in the ResourcesExportedToModel line (see the figure below).

localizer_1

In the opened dialog window, find the newly created localizer and activate its check-box as shown in the picture:

localizer_2

If you now open the Model Editor, a new node (Xafari|FeatureCenter) can be noticed in the Localization section for our localizer (see the image below).

localizer_4

The values of all localized properties can be modified in here in no time.