To Work with Multi-Language Fields

With MYOB Acumatica Framework, you can create fields into which a user can type values in multiple languages if multiple locales are configured in the applicable MYOB Acumatica Framework application. For example, in MYOB Acumatica, if an instance works with English and French locales, a user can specify the value of the Description box on the Stock Items (IN202500) form in English and French.

For details about multi-language fields on MYOB Acumatica forms, see Managing Locales and Languages.

To Configure a Field to Have Values in Multiple Languages

  1. In the data access class (DAC) that you want to contain a multi-language field, define the NoteID field with the PXNote attribute, as follows.
    public abstract class noteID : IBqlField { }
    
    [PXNote]
    public virtual Guid? NoteID { get; set; }
  2. If you want to configure a field to have values in multiple languages, annotate this field with the PXDBLocalizableString attribute. The following code shows an example of the use of the PXDBLocalizableString attribute.
    [PXDBLocalizableString(60, IsUnicode = true)]

    The PXDBLocalizableString attribute works similarly to the PXDBString attribute, but unlike the PXDBString attribute, the PXDBLocalizableString attribute can be used instead of the PXDBText and PXString attributes.

  3. If you need to give values in multiple languages to a field with the PXDBText attribute, replace this attribute with the PXDBLocalizableString attribute and do not specify the length parameter, as shown in the following example.
    [PXDBLocalizableString(IsUnicode = true)]
  4. If you need to configure a field that has the PXString attribute, which is used in conjunction with the PXDBCalced attribute, replace the PXString attribute with the PXDBLocalizableString attribute and set the value of the NonDB parameter to true, as shown in the following example.
    [PXDBLocalizableString(255, IsUnicode = true, NonDB = true, 
       BqlField = typeof(PaymentMethod.descr))] 
    [PXDBCalced(typeof(Switch<Case<Where<PaymentMethod.descr, IsNotNull>, 
       PaymentMethod.descr>, CustomerPaymentMethod.descr>), typeof(string))]

To Configure the Default Value of a Multi-Language Field

If you want a multi-language field to have a default value in a specific language, use the PXLocalizableDefault attribute instead of the PXDefault attribute and specify in its second parameter either a BQL field or a BQL select that provides language selection.

For example, in MYOB Acumatica, the SOLine line description defaulted to the appropriate InventoryItem description based on the language that is set for a customer. The TransactionDesr field of the SOLine DAC has the PXLocalizableDefault attribute with a second parameter that specifies the language as follows: typeof(Customer.languageName). See the following example of the use of the PXLocalizableDefault attribute.
[PXLocalizableDefault(typeof(Search<InventoryItem.descr,
   Where<InventoryItem.inventoryID, 
   Equal<Current<SOLine.inventoryID>>>>),
   typeof(Customer.languageName), 
   PersistingCheck = PXPersistingCheck.Nothing)]                                      

To Obtain the Value of a Multi-Language Field in the Current Locale

If you want to obtain the value of a multi-language field in the current locale, use the PXDatabase.SelectSingle() or PXDatabase.SelectMulti() method, and pass to it the return value of the PXDBLocalizableStringAttribute.GetValueSelect() static method instead of passing a new PXDataField object to it. (The PXDBLocalizableStringAttribute.GetValueSelect() method takes three input parameters: the table name, the field name, and a Boolean flag that indicates whether strings should be returned as text with unlimited length.)

The following code shows an example of the use of the PXDBLocalizableStringAttribute.GetValueSelect() method.
foreach (PXDataRecord record in PXDatabase.SelectMulti<Numbering>(
   newPXDataField<Numbering.numberingID>(), 
   PXDBLocalizableStringAttribute.GetValueSelect("Numbering", 
      "NewSymbol", false),
   newPXDataField<Numbering.userNumbering>()))     
{
   ...
}                                             
Note: Generally, you use the PXDatabase.SelectSingle() and PXDatabase.SelectMulti() methods for retrieving data within the Prefetch() method of a database slot. Remember to add language code to the slot key when you obtain a slot, as shown in the following example, because with the use of PXDBLocalizableStringAttribute, the data becomes language-specific. Therefore, you need different slot instances for different languages.
Numberings items = PXDatabase.GetSlot<Numberings>(
   typeof(Numberings).Name + currentLanguage, typeof(Numbering));

To Obtain the Value of a Multi-Language Field in a Specific Language

If you want to obtain the value of a multi-language field in a specific language, use the PXDBLocalizableStringAttribute.GetTranslation() method. Pass to the method as input parameters a DAC cache, a DAC instance, a field name, and the ISO code of the language.

The following code shows an example of use of the PXDBLocalizableStringAttribute.GetTranslation() method.
tran.TranDesc =
   PXDBLocalizableStringAttribute.GetTranslation(
      Caches[typeof(InventoryItem)], item, typeof(InventoryItem.descr).Name,
      customer.Current?.LanguageName);