PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

[PT Run] Localized file paths (Part 1): Update helper class and Program plugin

Open htcfreek opened this issue 3 years ago • 4 comments

Summary of the Pull Request

This PR implements localization of paths for Program plugin

image

... and the following improvements to the ShellLocalization helper:

  • Helper is now non-static.
  • Added cache to become faster.

ToDo items

  • [ ] fix lower case path for win32apps
  • [ ] fix lower case name for some win32 app types
  • [ ] some localized folder names are returned as short (~1) and not as long name
  • [ ] use loc path for context menu command "open ..."
  • [ ] fix bug that strings not always localized => #20026
  • [ ] check plugin times
  • [ ] Screenshots

PR Checklist

  • [x] Closes: #19521
  • [x] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [x] Tests: Added/updated and all pass
  • [x] Localization: All end user facing strings can be localized
  • [ ] Dev docs: Added/updated
  • [ ] New binaries: Added on the required places
  • [ ] Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Fixed invalid variable name in Win32Program.cs: LnkResolvedPath => LnkFilePath

Validation Steps Performed

Local build and test of functionality. Tests run and passed.

htcfreek avatar Aug 21 '22 13:08 htcfreek

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view or the :scroll:action log for details.

Unrecognized words (1)

cahce

Previously acknowledged words that are now absent APPLASTZONE autogenerated Cxxx FLASHZONES FLASHZONESONQUICKSWITCH fxcop LOADSTRING MOUSESWITCH MOVEWINDOWS QUICKLAYOUTSWITCH RESTORESIZE SHIFTDRAG testzones ZONECOLOR ZONEHIGHLIGHTCOLOR ZONESETCHANGE
To accept :heavy_check_mark: these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository on the PT_LocalizedPathProgram branch (:information_source: how do I use this?):

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1221550282" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" | tr -d "\\r" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

If the flagged items are false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it, try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

github-actions[bot] avatar Aug 21 '22 13:08 github-actions[bot]

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view or the :scroll:action log for details.

Unrecognized words (1)

executble

Previously acknowledged words that are now absent APPLASTZONE autogenerated Cxxx FLASHZONES FLASHZONESONQUICKSWITCH fxcop LOADSTRING MOUSESWITCH MOVEWINDOWS QUICKLAYOUTSWITCH RESTORESIZE SHIFTDRAG testzones ZONECOLOR ZONEHIGHLIGHTCOLOR ZONESETCHANGE
To accept :heavy_check_mark: these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository on the PT_LocalizedPathProgram branch (:information_source: how do I use this?):

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1221565809" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" | tr -d "\\r" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

If the flagged items are false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it, try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

github-actions[bot] avatar Aug 21 '22 15:08 github-actions[bot]

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view or the :scroll:action log for details.

Unrecognized words (1)

executble

Previously acknowledged words that are now absent APPLASTZONE autogenerated Cxxx FLASHZONES FLASHZONESONQUICKSWITCH fxcop LOADSTRING MOUSESWITCH MOVEWINDOWS QUICKLAYOUTSWITCH RESTORESIZE SHIFTDRAG testzones ZONECOLOR ZONEHIGHLIGHTCOLOR ZONESETCHANGE
To accept :heavy_check_mark: these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:htcfreek/PowerToys.git repository on the PT_LocalizedPathProgram branch (:information_source: how do I use this?):

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
-H "Content-Type: application/json" \
"https://api.github.com/repos/microsoft/PowerToys/issues/comments/1221567317" > "$comment_json"
comment_body=$(mktemp)
jq -r ".body // empty" "$comment_json" | tr -d "\\r" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")

patch_add=$(perl -e '$/=undef; $_=<>; if (m{Unrecognized words[^<]*</summary>\n*```\n*([^<]*)```\n*</details>$}m) { print "$1" } elsif (m{Unrecognized words[^<]*\n\n((?:\w.*\n)+)\n}m) { print "$1" };' < "$comment_body")

update_files
rm $comment_body
git add -u

If the flagged items are false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it, try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

github-actions[bot] avatar Aug 21 '22 15:08 github-actions[bot]

@crutkas , @jaimecbernardo For your information: At the moment I am a bit to busy for working on this. It will take some time to get it ready and fix all the bugs. Maybe Oktober or November.

htcfreek avatar Sep 19 '22 06:09 htcfreek

@crutkas , @jaimecbernardo Added "Status-Blocked" label because I have to investigate/try how to fix all the problems first. This will take some time and currently I am a bit to busy.

htcfreek avatar Nov 20 '22 22:11 htcfreek

Thanks for the heads up :)

jaimecbernardo avatar Nov 23 '22 09:11 jaimecbernardo

And thank you for the contributions ;)

jaimecbernardo avatar Nov 23 '22 09:11 jaimecbernardo

@Jay-o-Way , @Aaron-Junker I know that one of you had the problem that git submodule update was tracked as commit change. How did you fixed this?

htcfreek avatar Jan 27 '23 09:01 htcfreek

@Jay-o-Way , @Aaron-Junker I know that one of you had the problem that git submodule update was tracked as commit change. How did you fixed this?

@htcfreek https://github.com/microsoft/PowerToys/pull/20469#issuecomment-1374940597

noraa-junker avatar Jan 27 '23 09:01 noraa-junker

@Jay-o-Way , @Aaron-Junker I know that one of you had the problem that git submodule update was tracked as commit change. How did you fixed this?

@htcfreek #20469 (comment)

@Aaron-Junker Hmmm. 🤔 Sorry, but I don't unterstand what was going wrong. I synced my fork against main and did a git submodule update. Should I do the sub module update again?

htcfreek avatar Jan 27 '23 09:01 htcfreek

@Jay-o-Way , @Aaron-Junker I know that one of you had the problem that git submodule update was tracked as commit change. How did you fixed this?

@htcfreek #20469 (comment)

@Aaron-Junker Hmmm. 🤔 Sorry, but I don't unterstand what was going wrong. I synced my fork against main and did a git submodule update. Should I do the sub module update again?

@Aaron-Junker Fixed. The local clone was broken.

htcfreek avatar Jan 27 '23 10:01 htcfreek

@jaimecbernardo I have found a way to solve the translation problems and continue working on the rest of the PR.

htcfreek avatar Jan 27 '23 11:01 htcfreek

@jaimecbernardo With the changes in this PR/branch you should see localized results for program plugin (.wordpad).

htcfreek avatar Feb 13 '23 10:02 htcfreek

Hi @htcfreek, Thanks for this contribution, this one works for me: image image And you can search it with both names, which is pretty nice: image

The Windows Search one doesn't: https://github.com/microsoft/PowerToys/pull/23665#issuecomment-1427708723

jaimecbernardo avatar Feb 13 '23 10:02 jaimecbernardo

@htcfreek , anything you want to check before bringing this one in?

jaimecbernardo avatar Feb 13 '23 10:02 jaimecbernardo

@jaimecbernardo You can merge this PR.

htcfreek avatar Feb 13 '23 11:02 htcfreek