Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LT-21963: Copy Malay to an alternate writing system code (ms -> zlm) #237

Open
wants to merge 5 commits into
base: release/9.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Build/Installer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<L10nFiles Include="$(OutputDirForConfig)\ur\**\*"/>
<L10nFiles Include="$(OutputDirForConfig)\vi\**\*"/>
<L10nFiles Include="$(OutputDirForConfig)\zh-CN\**\*"/>
<L10nFiles Include="$(OutputDirForConfig)\zlm\**\*"/>
<!-- no need to install the following; most are installed by merge modules -->
<MergeModules Include="$(OutputDirForConfig)\asserts.log"/>
<MergeModules Include="$(OutputDirForConfig)\basicTest.xml"/>
Expand Down
6 changes: 5 additions & 1 deletion Build/Localize.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="Current">

<UsingTask TaskName="CopyLocale" AssemblyFile="FwBuildTasks.dll"/>
<UsingTask TaskName="GoldEticToXliff" AssemblyFile="FwBuildTasks.dll"/>
<UsingTask TaskName="ListsToXliff" AssemblyFile="FwBuildTasks.dll"/>
<UsingTask TaskName="LocalizeFieldWorks" AssemblyFile="FwBuildTasks.dll"/>
Expand All @@ -13,7 +14,7 @@

<!-- Localize strings-en.xml, lists, and all resx files -->
<Target Name="localize" DependsOnTargets="localize-source;localize-binaries"/>
<Target Name="localize-source" DependsOnTargets="Initialize;downloadTranslatedFiles;copyLibL10ns;combineGOLDEtic;zipLocalizedLists;processLanguages-source" Condition="'$(DisableLocalization)'!='true'"/>
<Target Name="localize-source" DependsOnTargets="Initialize;downloadTranslatedFiles;copyLibL10ns;combineGOLDEtic;zipLocalizedLists;copyLocales;processLanguages-source" Condition="'$(DisableLocalization)'!='true'"/>
<Target Name="localize-binaries" DependsOnTargets="Initialize;processLanguages-binaries" Condition="'$(DisableLocalization)'!='true'"/>

<PropertyGroup>
Expand All @@ -34,6 +35,9 @@
<!-- Install overcrowdin, or update if already installed. -->
<Exec WorkingDirectory="$(fwrt)" Command="dotnet tool update -g overcrowdin || dotnet tool install -g overcrowdin"/>
</Target>
<Target Name="copyLocales"> <!-- Copy locales to alternate ws identifiers -->
<CopyLocale SourceL10n="$(L10nsDirectory)/ms" DestL10n="$(L10nsDirectory)/zlm" LcmDir="$(LcmSrcDir)" />
</Target>

<!-- Update localizable files in Crowdin -->
<Target Name="uploadUpdatesForTranslation" DependsOnTargets="CopyLcmResxFiles;InstallOvercrowdin">
Expand Down
4 changes: 2 additions & 2 deletions Build/Src/FwBuildTasks/FwBuildTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<RootNamespace>SIL.FieldWorks.Build.Tasks</RootNamespace>
<Description>Additional msbuild tasks for FieldWorks</Description>
<Product>FwBuildTasks</Product>
<TargetFramework>net461</TargetFramework>
<TargetFramework>net462</TargetFramework>
<OutputPath>../..</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" PrivateAssets="All" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
Copy link

@hahn-kev hahn-kev Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would double check this version of the adapter works (it might silently fail and not run any tests), I believe only 4.3.2 supports this version of NUnit but I may be thinking of the dotnet version in which case I'm not sure if version 4.3.2 is only required for net461

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it did work, adding this allowed John to run the tests in visual studio without Resharper. I bumped this up to 462 since it was missed in the earlier round of updates. It looks like NUnit3TestAdapter at this version supports 462.

<PackageReference Include="SIL.TestUtilities" Version="12.0.0-*" PrivateAssets="All" />
<Reference Include="netstandard" />
<Reference Include="Microsoft.Build.Framework" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 SIL International
// Copyright (c) 2020 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -60,6 +60,19 @@ public void Works()
VerifyLocale("zh-CN", "zh");
}

[Test]
public void CopyMalay()
{
FileSystemSetup(new[] { "ms" });

VerifyLocale("ms", "zlm");

_task.Execute();

VerifyLocale("ms", "zzz");
VerifyLocale("zlm", "zzz");
}

private void FileSystemSetup(string[] locales)
{
foreach (var locale in locales)
Expand Down
105 changes: 105 additions & 0 deletions Build/Src/FwBuildTasks/Localization/CopyLocale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) 2024 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;


namespace SIL.FieldWorks.Build.Tasks.Localization
{
public class CopyLocale : Task
{
[Required]
public string SourceL10n { get; set; }

[Required]
public string DestL10n { get; set; }

[Required]
public string LcmDir { get; set; }

public override bool Execute()
{
var srcLangCode = Path.GetFileName(SourceL10n);
var destLangCode = Path.GetFileName(DestL10n);
if (!Directory.Exists(SourceL10n))
{
Log.LogError($"Source directory '{SourceL10n}' does not exist.");
return false;
}
if (Directory.Exists(DestL10n))
{
Log.LogError($"Destination directory '{DestL10n}' already exists.");
return false;
}
// Create the destination directory
Directory.CreateDirectory(DestL10n);

// Get the files in the source directory and copy to the destination directory
CopyDirectory(SourceL10n, DestL10n, true);

NormalizeLocales.RenameLocaleFiles(DestL10n, srcLangCode, destLangCode);
// Get the files in the source directory and copy to the destination directory
foreach (var file in Directory.GetFiles(LcmDir, "*.resx", SearchOption.AllDirectories))
{
var relativePath = GetRelativePath(LcmDir, file);
Log.LogMessage(MessageImportance.Normal, "CopyLocale: relpath - " + relativePath);
var newFileName = Path.GetFileNameWithoutExtension(file) + $".{destLangCode}.resx";
var newFilePath = Path.Combine(DestL10n, Path.Combine("Src", Path.GetDirectoryName(relativePath)));

// Create the directory for the new file if it doesn't exist
Directory.CreateDirectory(newFilePath);

Log.LogMessage(MessageImportance.Normal, $"CopyLocale: {newFilePath}, {newFileName}");
// Copy the file to the new location
File.Move(file, Path.Combine(newFilePath, newFileName));
}

return true;
}

static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
{
// From: https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories
// Get information about the source directory
var dir = new DirectoryInfo(sourceDir);

// Check if the source directory exists
if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");

// Cache directories before we start copying
DirectoryInfo[] dirs = dir.GetDirectories();

// Create the destination directory
Directory.CreateDirectory(destinationDir);

// Get the files in the source directory and copy to the destination directory
foreach (FileInfo file in dir.GetFiles())
{
string targetFilePath = Path.Combine(destinationDir, file.Name);
file.CopyTo(targetFilePath);
}

// If recursive and copying subdirectories, recursively call this method
if (recursive)
{
foreach (DirectoryInfo subDir in dirs)
{
string newDestinationDir = Path.Combine(destinationDir, subDir.Name);
CopyDirectory(subDir.FullName, newDestinationDir, true);
}
}
}

static string GetRelativePath(string baseDir, string filePath)
{
Uri baseUri = new Uri(baseDir);
Uri fileUri = new Uri(filePath);
return Uri.UnescapeDataString(baseUri.MakeRelativeUri(fileUri).ToString().Replace('/', Path.DirectorySeparatorChar));
}
}
}
9 changes: 7 additions & 2 deletions Build/Src/FwBuildTasks/Localization/NormalizeLocales.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public override bool Execute()
var locales = Directory.GetDirectories(L10nsDirectory).Select(Path.GetFileName);
foreach (var locale in locales)
{
RenameLocale(locale, Normalize(locale));
var normalizedLocale = Normalize(locale);
RenameLocale(locale, normalizedLocale);
}
return true;
}
Expand All @@ -49,8 +50,12 @@ private void RenameLocale(string source, string dest)
var sourceDir = Path.Combine(L10nsDirectory, source);
var destDir = Path.Combine(L10nsDirectory, dest);
Directory.Move(sourceDir, destDir);
RenameLocaleFiles(destDir, source, dest);
}

foreach (var file in Directory.EnumerateFiles(destDir, "*", SearchOption.AllDirectories))
internal static void RenameLocaleFiles(string destDirName, string source, string dest, string extension = "*")
{
foreach (var file in Directory.EnumerateFiles(destDirName, extension, SearchOption.AllDirectories))
{
var nameNoExt = Path.GetFileNameWithoutExtension(file);
// ReSharper disable once PossibleNullReferenceException - no files are null
Expand Down
4 changes: 4 additions & 0 deletions FLExInstaller/CustomComponents.wxi
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<Directory Id="urL10NFOLDER" Name="ur"/>
<Directory Id="viL10NFOLDER" Name="vi"/>
<Directory Id="zhL10NFOLDER" Name="zh-CN"/>
<Directory Id="zlmL10NFOLDER" Name="zlm"/>
</DirectoryRef>

<DirectoryRef Id='HARVESTDATAFOLDER'>
Expand Down Expand Up @@ -225,6 +226,7 @@
<WixVariable Id="MASTERurL10NDIR" Value="$(var.MASTERBUILDDIR)_L10n\ur"/>
<WixVariable Id="MASTERviL10NDIR" Value="$(var.MASTERBUILDDIR)_L10n\vi"/>
<WixVariable Id="MASTERzhL10NDIR" Value="$(var.MASTERBUILDDIR)_L10n\zh-CN"/>
<WixVariable Id="MASTERzlmL10NDIR" Value="$(var.MASTERBUILDDIR)_L10n\zlm"/>
<WixVariable Id="MASTERFONTDIR" Value="$(var.MASTERBUILDDIR)_Font"/>
<?define HarvestWxiDir = .\master?>
<?else?>
Expand Down Expand Up @@ -254,6 +256,7 @@
<WixVariable Id="UPDATEurL10NDIR" Value="$(var.UPDATEBUILDDIR)_L10n\ur"/>
<WixVariable Id="UPDATEviL10NDIR" Value="$(var.UPDATEBUILDDIR)_L10n\vi"/>
<WixVariable Id="UPDATEzhL10NDIR" Value="$(var.UPDATEBUILDDIR)_L10n\zh-CN"/>
<WixVariable Id="UPDATEzlmL10NDIR" Value="$(var.UPDATEBUILDDIR)_L10n\zlm"/>
<WixVariable Id="UPDATEFONTDIR" Value="$(var.UPDATEBUILDDIR)_Font"/>
<?define HarvestWxiDir = .\update?>
<?endif?>
Expand Down Expand Up @@ -284,5 +287,6 @@
<?include $(var.HarvestWxiDir)\urHarvest.wxi?>
<?include $(var.HarvestWxiDir)\viHarvest.wxi?>
<?include $(var.HarvestWxiDir)\zhHarvest.wxi?>
<?include $(var.HarvestWxiDir)\zlmHarvest.wxi?>
<?include Fonts.wxi?>
</Include>
Loading