-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormat.Resx.fs
36 lines (32 loc) · 965 Bytes
/
Format.Resx.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Resx
open System
open System.IO
open System.Text
open Resx.Resources
open Model
let private getPath name lang =
Option.defaultValue "Resources" name
|> match lang with
| Column.Default -> sprintf "%s.resx"
| s -> (fun f -> sprintf "%s.%s.resx" f s)
let private formatPhrases ph phrases =
let sb = StringBuilder ()
let typeConverter (t:Type) =
t.FullName.Replace("Resx.Resources.", "System.Resources.")
use writer = new ResXResourceWriter (new StringWriter (sb), typeConverter)
let createNode t =
let value:string = t.Value |> ph (sprintf "{%i}")
let node = ResXDataNode (t.Key,value,null)
match (t.Comment) with
| Some c -> node.Comment <- c; node
| None -> node
phrases
|> Seq.map createNode
|> Seq.iter writer.AddResource
writer.Close ()
sb.ToString ()
let format name ph lang phrases = {
Path = (getPath name lang)
Contents = (formatPhrases ph phrases)
Phrases = Seq.length phrases
}