-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[General]Support language selection (#34971)
* Language setting * spellcheck * Set FileLocksmithContextMenu package version in AppManifest.xml * Fix ambigious symbol build error * Fix ambigious symbol build error #2 * Revert unneeded changes * Improve perf * try fix ci build
- Loading branch information
1 parent
2b4b55c
commit 5b616c9
Showing
38 changed files
with
754 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1557,7 +1557,7 @@ Stubless | |
STYLECHANGED | ||
STYLECHANGING | ||
subkeys | ||
SUBLANG | ||
sublang | ||
subquery | ||
Superbar | ||
sut | ||
|
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,50 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.IO.Abstractions; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ManagedCommon | ||
{ | ||
public static class LanguageHelper | ||
{ | ||
public const string SettingsFilePath = "\\Microsoft\\PowerToys\\"; | ||
public const string SettingsFile = "language.json"; | ||
|
||
internal sealed class OutGoingLanguageSettings | ||
{ | ||
[JsonPropertyName("language")] | ||
public string LanguageTag { get; set; } | ||
} | ||
|
||
public static string LoadLanguage() | ||
{ | ||
FileSystem fileSystem = new FileSystem(); | ||
var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
var file = localAppDataDir + SettingsFilePath + SettingsFile; | ||
|
||
if (fileSystem.File.Exists(file)) | ||
{ | ||
try | ||
{ | ||
Stream inputStream = fileSystem.File.Open(file, FileMode.Open); | ||
StreamReader reader = new StreamReader(inputStream); | ||
string data = reader.ReadToEnd(); | ||
inputStream.Close(); | ||
reader.Dispose(); | ||
|
||
return JsonSerializer.Deserialize<OutGoingLanguageSettings>(data).LanguageTag; | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} |
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,22 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <common/SettingsAPI/settings_helpers.h> | ||
#include <common/utils/json.h> | ||
|
||
namespace LanguageHelpers | ||
{ | ||
inline std::wstring load_language() | ||
{ | ||
std::filesystem::path languageJsonFilePath(PTSettingsHelper::get_root_save_folder_location() + L"\\language.json"); | ||
|
||
auto langJson = json::from_file(languageJsonFilePath.c_str()); | ||
if (!langJson.has_value()) | ||
{ | ||
return {}; | ||
} | ||
|
||
std::wstring language = langJson->GetNamedString(L"language", L"").c_str(); | ||
return language; | ||
} | ||
} |
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
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.