Skip to content

Frontend tweaks2 #2

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

Open
wants to merge 5 commits into
base: bugfix/crash-when-no-key
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions LocalizationCompiler/Ids.Parsers.XliffGenerator/HtmlCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module Generators =
let private deTag (t : LocalizationSourcePart) : string =
match t with
| Text s -> s
| Variable s -> "{{" + s + "}}"
| Variable s -> s

Copy link

@JamesFaix JamesFaix Oct 8, 2017

Choose a reason for hiding this comment

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

If in both cases we return the input, this function isn't really doing anything.

In C# this function would be kinda like:

enum LocalizationSourcePartType { Text, Variable }

string deTag(LocalizationSourcePart t)
{
    if (t.LocalizationSourcePartType == LocalizationSourcePartType.Text) {
        var s = (string)t;
        return s;
    }
    if (t.LocalizationSourcePartType == LocalizationSourcePartType.Variable)
    {
        var s = (string)t;
        return s;
    }
    
    throw new Exception("This can never be hit because of the enum values");
}

Copy link
Author

Choose a reason for hiding this comment

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

So, it still does map a LocalizationSourcePart to either its Text or Variable property. Is there a more elegant way to do that?

Choose a reason for hiding this comment

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

@distinctdan The more I look at it, I think this function is actually required to appease the compiler's type checker. Even thought a LocalizationSourcePart is effectively a string, you still need a mapping function to String. The name deTag isn't really appropriate though.

Choose a reason for hiding this comment

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

I would just call is asString or stringify or something (because ToString is already a default method in .NET which will return the type name here I believe.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I'd agree. I'm thinking I'll leave it alone for now since we're wanting to make some significant revisions to the compiler anyways in the future as well.

let private deTagAttr (t : LocalizationSourcePart) : string =
match t with
Expand Down Expand Up @@ -109,5 +109,11 @@ module Generators =
let rest = Text.NormalizeNewlines(contents).Substring(int32(endPosition.Index))
match x with
| [] -> rest
| x -> (x |> Seq.map(fun (leader, tag) -> (leader, generateIdTag(tag))) |> Seq.map (fun (leader, tag) -> leader + (getTranslation matches tag)) |> Seq.reduce (+)) + rest
| x -> (x
|> Seq.map(fun (leader, tag) -> (leader, generateIdTag(tag)))
// DS: The Trim() is there because the xml generator puts a variable on a new line
// if the string starts with a variable, which messes up js formatting because
// js strings can only be on one line.
|> Seq.map (fun (leader, tag) -> leader + (getTranslation matches tag).Trim())
|> Seq.reduce (+)) + rest
| Failure (reasons, state, _) -> reasons
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module XliffGenerator =

member x.Generate originalFileName (localizationTags : LocalizationTag seq) =
fileNodeOriginalAttribute.Value <- originalFileName
targetLanguageAttribute.Value <- "en-US"
targetLanguageAttribute.Value <- "en"

localizationTags |> Seq.map generateIdTag |> Seq.iter tagToXmlElement

Expand Down
2 changes: 2 additions & 0 deletions LocalizationCompiler/LocalizationCompiler.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ Global
{357E9998-74F6-48FD-8A08-6929114791BE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{357E9998-74F6-48FD-8A08-6929114791BE}.Release|x86.ActiveCfg = Release|Any CPU
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Debug|Any CPU.ActiveCfg = Debug|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Debug|Any CPU.Build.0 = Debug|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Debug|Mixed Platforms.Build.0 = Debug|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Debug|x86.ActiveCfg = Debug|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Debug|x86.Build.0 = Debug|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Release|Any CPU.ActiveCfg = Release|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Release|Any CPU.Build.0 = Release|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Release|Mixed Platforms.ActiveCfg = Release|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Release|Mixed Platforms.Build.0 = Release|x86
{C74568BA-270A-4D22-8603-9A5321E50F1A}.Release|x86.ActiveCfg = Release|x86
Expand Down
9 changes: 5 additions & 4 deletions LocalizationCompiler/LocalizationCompiler/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ module Program =
open Ids.Generators
open Ids.Localization.Parsers
open Ids.Localization.Parsers.XliffGenerator.XliffGenerator
open System.Text.RegularExpressions

let supportedFileTypes = new Regex("htm|html|js")

let rec generateXlfFromFiles (d : DirectoryInfo) (x : XliffGenerator) =
printfn "%s" d.FullName
let r = new System.Text.RegularExpressions.Regex("htm|html")
d.EnumerateFiles()
|> Seq.filter(fun f -> r.IsMatch(f.Extension))
|> Seq.filter(fun f -> supportedFileTypes.IsMatch(f.Extension))
|> Seq.iter(fun f ->
printfn "\t%s" f.Name
x.Generate f.Name (LocalizationTagParser.parse (File.ReadAllText(f.FullName))) |> ignore)
Expand All @@ -39,12 +41,11 @@ module Program =

let rec generateApplicationFromXlf (tags : LocalizationMatch seq) (applicationDirectory : DirectoryInfo) (outputDirectory : DirectoryInfo) =
printfn "%s" applicationDirectory.FullName
let r = new System.Text.RegularExpressions.Regex("htm|html")

applicationDirectory.EnumerateFiles()
|> Seq.iter(fun f ->
let outputName = Path.Combine(outputDirectory.FullName, f.Name)
if f.Extension |> r.IsMatch then
if f.Extension |> supportedFileTypes.IsMatch then
printMatchedFile f

let newContents = HtmlCompiler.generateNewHtmlFile (File.ReadAllText f.FullName) tags
Expand Down