-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractorStringsBlueprint.ps1
57 lines (42 loc) · 1.5 KB
/
ExtractorStringsBlueprint.ps1
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
$REGEX = '_\("(.*)"\)' # Regex to detect _("localized strings")
$build = Get-Content -Raw ./build.json | ConvertFrom-Json
$config = Get-Content -Raw ./config.json | ConvertFrom-Json
$BLUEPRINT_FOLDER = $build.BLUEPRINT_FOLDER
$BLUEPRINT_POT_PATH = $build.BLUEPRINT_POT_PATH
$APP_DISPLAY_NAME = $config.APP_DISPLAY_NAME
$hashTable = @{}
if (Test-Path $BLUEPRINT_POT_PATH)
{
Remove-Item $BLUEPRINT_POT_PATH
}
$labels = Get-ChildItem -Path $BLUEPRINT_FOLDER -Filter *.blp -Recurse | Select-String -Pattern $REGEX | Select-Object -Property Filename,LineNumber,Matches
foreach ($label in $labels)
{
$key = $label.Matches.Groups[1].Value
if (!$hashTable.ContainsKey($key))
{
$hashTable.Add($key, [System.Collections.ArrayList]::new())
}
$hashTable[$key].Add($label.Filename + ":" + $label.LineNumber)
}
[string]$file = 'msgid ""
msgstr ""
"Project-Id-Version: {0}\n"
"POT-Creation-Date: {1}\n"
"PO-Revision-Date: {1}\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Powershell script\n"' -f $APP_DISPLAY_NAME, (Get-Date -Format "yyyy-MM-dd HH:mm:ssK")
Add-Content $BLUEPRINT_POT_PATH ($file + "`n")
foreach($element in $hashTable.GetEnumerator())
{
foreach($item in $element.Value)
{
Add-Content $BLUEPRINT_POT_PATH ("#: " + $item)
}
Add-Content $BLUEPRINT_POT_PATH ('msgid "' + $element.Name + '"')
Add-Content $BLUEPRINT_POT_PATH ('msgstr ""' + "`n")
}