Skip to content

Commit 2a00261

Browse files
authored
fix and improves l10n (#1181)
1 parent eaa9e0b commit 2a00261

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

src/FsAutoComplete.Core/TipFormatter.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,26 @@ let rec private readXmlDoc (reader: XmlReader) (indentationSize: int) (acc: Map<
895895
let private xmlDocCache =
896896
Collections.Concurrent.ConcurrentDictionary<string, Map<string, XmlDocMember>>()
897897

898+
let private findCultures v =
899+
let rec loop state (v: System.Globalization.CultureInfo) =
900+
let state' = v.Name :: state
901+
902+
if v.Parent = System.Globalization.CultureInfo.InvariantCulture then
903+
"" :: state' |> List.rev
904+
else
905+
loop state' v.Parent
906+
907+
loop [] v
908+
909+
let private findLocalizedXmlFile (xmlFile: string) =
910+
let xmlName = Path.GetFileName xmlFile
911+
let path = Path.GetDirectoryName xmlFile
912+
913+
findCultures System.Globalization.CultureInfo.CurrentUICulture
914+
|> List.map (fun culture -> Path.Combine(path, culture, xmlName))
915+
|> List.tryFind (fun i -> File.Exists i)
916+
|> Option.defaultValue xmlFile
917+
898918
let private getXmlDoc dllFile =
899919
let xmlFile = Path.ChangeExtension(dllFile, ".xml")
900920
//Workaround for netstandard.dll
@@ -908,6 +928,8 @@ let private getXmlDoc dllFile =
908928
else
909929
xmlFile
910930

931+
let xmlFile = findLocalizedXmlFile xmlFile
932+
911933
if xmlDocCache.ContainsKey xmlFile then
912934
Some xmlDocCache.[xmlFile]
913935
else

src/FsAutoComplete/CodeFixes.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ module Run =
326326
let ifDiagnosticByMessage (checkMessage: string) handler : CodeFix =
327327
runDiagnostics (fun d -> d.Message.Contains checkMessage) handler
328328

329+
let ifDiagnosticByCheckMessage (checkMessageFunc: (string -> bool) list) handler : CodeFix =
330+
runDiagnostics (fun d -> checkMessageFunc |> List.exists (fun f -> f d.Message)) handler
331+
329332
let ifDiagnosticByType (diagnosticType: string) handler : CodeFix =
330333
runDiagnostics
331334
(fun d ->

src/FsAutoComplete/CodeFixes.fsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ module Run =
162162
handler: (Diagnostic -> CodeActionParams -> Async<Result<Fix list, string>>) ->
163163
(CodeActionParams -> Async<Result<Fix list, string>>)
164164

165+
val ifDiagnosticByCheckMessage:
166+
checkMessageFunc: (string -> bool) list ->
167+
handler: (Diagnostic -> CodeActionParams -> Async<Result<Fix list, string>>) ->
168+
(CodeActionParams -> Async<Result<Fix list, string>>)
169+
165170
val ifDiagnosticByType:
166171
diagnosticType: string ->
167172
handler: (Diagnostic -> CodeActionParams -> Async<Result<Fix list, string>>) ->

src/FsAutoComplete/CodeFixes/ReplaceWithSuggestion.fs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,27 @@ open FSharp.Compiler.Syntax
88

99
let title suggestion = $"Replace with '%s{suggestion}'"
1010

11+
let undefinedName =
12+
[ "Maybe you want one of the following:"
13+
"Možná budete potřebovat něco z tohoto:"
14+
"Vielleicht möchten Sie eine der folgenden Bezeichnungen verwenden:"
15+
"Puede elegir una de las opciones siguientes:"
16+
"Peut-être souhaitez-vous l'une des options suivantes :"
17+
"Si può specificare uno dei nomi seguenti:"
18+
"次のいずれかの可能性はありませんか:"
19+
"다음 중 하나가 필요할 수 있습니다:"
20+
"Możliwe, że chcesz wykonać jedną z następujących czynności:"
21+
"Talvez você queira um dos seguintes:"
22+
"Возможно, требуется одно из следующих:"
23+
"Aşağıdakilerden birini arıyor olabilirsiniz:"
24+
"你可能需要以下之一:"
25+
"您可能需要下列其中一項:" ]
26+
|> List.map (fun i -> fun (j: string) -> j.Contains(i, System.StringComparison.Ordinal))
27+
1128
/// a codefix that replaces the use of an unknown identifier with a suggested identifier
1229
let fix =
13-
Run.ifDiagnosticByMessage "Maybe you want one of the following:" (fun diagnostic codeActionParams ->
14-
diagnostic.Message.Split('\n').[1..]
30+
Run.ifDiagnosticByCheckMessage undefinedName (fun diagnostic codeActionParams ->
31+
diagnostic.Message.Split('\n', '\u001b').[1..]
1532
|> Array.map (fun suggestion ->
1633
let suggestion = suggestion.Trim() |> PrettyNaming.NormalizeIdentifierBackticks
1734

src/FsAutoComplete/CodeFixes/ResolveNamespace.fs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,29 @@ open FsAutoComplete.LspHelpers
99
open FsAutoComplete
1010
open FSharp.Compiler.Text
1111
open FSharp.Compiler.EditorServices
12+
open System.Text.RegularExpressions
1213

1314
type LineText = string
1415

16+
let undefinedName =
17+
[ "not define"
18+
"nedefinuje|Není definovaný|Není definované|Není definovaná|Nemáte definovaný"
19+
"definiert nicht|nicht.*? definiert"
20+
"no define|no está definido|no está definida"
21+
"ne définit|n'est pas défini"
22+
"non definisce|non è definito|non è definita"
23+
"定義(され|し)ていません"
24+
"정의(하지 않|되지 않았|되어 있지 않)습니다"
25+
"nie definiuje|Nie zdefiniowano|nie jest zdefiniowany"
26+
"não define|não está definido"
27+
"не определяет|не определено|не определены|не определен"
28+
"tanımlamıyor|tanımlı değil"
29+
"未.*?定义"
30+
"未定義" ]
31+
|> List.map (fun i ->
32+
let regex = Regex(i, RegexOptions.IgnoreCase ||| RegexOptions.Compiled)
33+
fun (j: string) -> regex.IsMatch(j))
34+
1535
/// a codefix the provides suggestions for opening modules or using qualified names when an identifier is found that needs qualification
1636
let fix
1737
(getParseResultsForFile: GetParseResultsForFile)
@@ -120,7 +140,7 @@ let fix
120140
Title = $"open %s{actualOpen}"
121141
Kind = FixKind.Fix }
122142

123-
Run.ifDiagnosticByMessage "is not defined" (fun diagnostic codeActionParameter ->
143+
Run.ifDiagnosticByCheckMessage undefinedName (fun diagnostic codeActionParameter ->
124144
asyncResult {
125145
let pos = protocolPosToPos diagnostic.Range.Start
126146

0 commit comments

Comments
 (0)