Showing posts with label Labels. Show all posts
Showing posts with label Labels. Show all posts

Tuesday, 5 June 2018

Import label files X++

Following job can be used to import multiple label files from a folder. The label files are not automatically saved in AOT so a manual Save all is required.

static void LabelFileImport(Args _args)
{
    #File
    
    FilePath                        directoryPath, filePath;
    Filename                        fileName, fileNameWithPath;
    SysLabelFile                    labelFile;
    Set                             languages;    
    
    System.String[]                 files;
    System.Collections.IEnumerator  enumerator;
    
    directoryPath = @"D:\TempNav\LabelFiles"; // folder to import from
    info(strFmt("Import path: %1", directoryPath));
    
    try
    {
        files = System.IO.Directory::GetFiles(directoryPath, '*.ald');
        enumerator = files.GetEnumerator();
    }
    catch
    {
        info(strFmt("Failed to get file list from path %1", directoryPath));
    }
    
    if (enumerator)
    {
        while (enumerator.MoveNext())
        {
            fileNameWithPath = enumerator.get_Current();
            
            try
            {
                [filePath, fileName] = fileNameSplit(fileNameWithPath);
                
                labelFile = SysLabelFile::newFilename(fileNameWithPath);
                languages = new Set(Types::String);
                languages.add(labelFile.parmLanguageId());
        
                SysLabelFile::createLabelFileInAOT(labelFile.parmModuleId(), languages);
                labelFile.importAldFile(fileNameWithPath);
        
                info(strFmt("@SYS322092", fileName));
            }
            catch
            {
                info(strFmt("Filed to import file %1", fileName));
            }
        }
    }
}

This posting is provided "AS IS" with no warranties. Use code at your own risk.

Tuesday, 22 May 2018

Export label files X++

Following job can be used to export multiple label files of a particular language to a folder. There is an option to save the files as a different language file as well (in case the files are to be used for translation or to be imported as different language)

static void LabelFileExport(Args _args)
{
    #File

    SysLabelFile    sysLabelFile;
    str             labelModule, labelFileName, labelLanguage;
    str             labelSaveAsLanguage, labelSaveAsFileName;
    container       labelModuleCon;
    int             i;
    FilePath        path;
    FileName        fileName;

    path                = @"D:\TempNav\LabelFiles"; // folder to export to
    labelModuleCon      = str2con("ASC,ASG"); // labels to export
    labelLanguage       = "en-us";
    labelSaveAsLanguage = "en-za"; // set as "" to export with original language name

    if (!strEndsWith(path, #FilePathDelimiter))
    {
        path += #FilePathDelimiter;
    }
    info(strFmt("Export path: %1", path));

    for (i = 1; i <= conLen(labelModuleCon); i++)
    {
        labelModule = conPeek(labelModuleCon, i);

        try
        {
            labelFileName = strFmt("Ax%1%2.ald", labelModule, labelLanguage);

            if (labelSaveAsLanguage != "")
            {
                labelSaveAsFileName = strFmt("Ax%1%2.ald", labelModule, labelSaveAsLanguage);
                fileName = path + labelSaveAsFileName;
            }
            else
            {
                fileName = path + labelFileName;
            }

            sysLabelFile = SysLabelFile::newFilename(labelFileName);
            sysLabelFile.toFile(fileName);

            if (labelSaveAsLanguage != "")
            {
                info(strFmt("Successfully exported label file %1 as %2", labelFileName, labelSaveAsFileName));
            }
            else
            {
                info(strFmt("Successfully exported label file %1", labelFileName));
            }
        }
        catch
        {
            info(strFmt("Failed to export label file %1", labelFileName));
        }
    }
}

This posting is provided "AS IS" with no warranties. Use code at your own risk.