-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
jasonleenaylor
wants to merge
5
commits into
release/9.1
Choose a base branch
from
LT-21963
base: release/9.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−6
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
266b566
LT-21963: Add code to copy ms to zlm
jtmaxwell3 9db6b73
Copy directories recursively
jtmaxwell3 b74acf5
Fix folder rename logic (use the normalized folder name)
jasonleenaylor e2bb08b
Refactor the locale copying code and add 'zlm' to the installer
jasonleenaylor ad68e2d
Merge branch 'release/9.1' into LT-21963
JakeOliver28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 version4.3.2
is only required for net461There was a problem hiding this comment.
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.