blob: 6241e42fe6db75bb718d6f1ea0c2679e60ef0015 (
plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
Clear-Host
$CYAN = "Cyan"
$GREEN = "Green"
$YELLOW = "Yellow"
$BLUE = "Blue"
$PURPLE = "Magenta"
$RED = "Red"
$LANG_CODE = "ja"
function Write-Color {
param (
[string]$Text,
[string]$Color = "White"
)
Write-Host $Text -ForegroundColor $Color
}
Write-Color " ████████╗██████╗ █████╗ ███╗ ██╗███████╗██╗ █████╗ ████████╗███████╗" $CYAN
Write-Color " ╚══██╔══╝██╔══██╗██╔══██╗████╗ ██║██╔════╝██║ ██╔══██╗╚══██╔══╝██╔════╝" $CYAN
Write-Color " ██║ ██████╔╝███████║██╔██╗ ██║███████╗██║ ███████║ ██║ █████╗ " $CYAN
Write-Color " ██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║██║ ██╔══██║ ██║ ██╔══╝ " $CYAN
Write-Color " ██║ ██║ ██║██║ ██║██║ ╚████║███████║███████╗██║ ██║ ██║ ███████╗" $CYAN
Write-Color " ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝" $CYAN
Write-Color ""
Write-Color " ᕕ(⌐■_■)ᕗ Locale generation tool for Japanese templates" $PURPLE
Write-Color ""
function Generate-Messages {
Write-Color ""
Write-Color "Generating translation messages for $LANG_CODE (HTML templates and Python files)..." $YELLOW
Write-Color ""
python manage.py makemessages -l $LANG_CODE -e html,py --ignore templates.old/* --ignore venv/* --ignore env/* --ignore .venv/*
if ($LASTEXITCODE -ne 0) {
Write-Color "Error: makemessages failed" $RED
exit 1
}
Write-Color ""
Write-Color "✓ Translation message files successfully generated!" $GREEN
Write-Color "You can now edit the .po files in locale/$LANG_CODE/LC_MESSAGES/" $BLUE
Write-Color ""
}
function Compile-Messages {
$localePath = "locale/$LANG_CODE/LC_MESSAGES"
Write-Color ""
Write-Color "Compiling translation messages for $LANG_CODE..." $YELLOW
Write-Color ""
if (-not (Test-Path $localePath)) {
Write-Color "Error: $localePath directory not found." $RED
exit 1
}
Push-Location $localePath
if (-not (Test-Path django.po)) {
Write-Color "Error: django.po not found." $RED
Write-Color "Tip: Run the generate option first to create translation files." $YELLOW
Pop-Location
exit 1
}
Write-Color "Compiling django.po..." $BLUE
msgfmt django.po -o django.mo
if ($LASTEXITCODE -ne 0) {
Write-Color "Error: Failed to compile django.po" $RED
Pop-Location
exit 1
}
Write-Color "✓ Compiled django.mo successfully." $GREEN
Pop-Location
Write-Color ""
Write-Color "✓ Translation messages compilation complete!" $GREEN
Write-Color ""
}
if ($args.Count -gt 0) {
if ($args[0] -eq "-g") {
Generate-Messages
}
elseif ($args[0] -eq "-c") {
Compile-Messages
}
else {
Write-Color "Invalid option. Use -g or -c." $RED
exit 1
}
}
else {
Write-Color "What do you want to do?" $CYAN
Write-Color " g - Generate translation messages" $GREEN
Write-Color " c - Compile translation messages" $BLUE
Write-Host -NoNewline "Choose an option " -ForegroundColor $YELLOW
Write-Host -NoNewline "[" -ForegroundColor White
Write-Host -NoNewline "g" -ForegroundColor $GREEN
Write-Host -NoNewline "]: " -ForegroundColor White
$action = Read-Host
if ([string]::IsNullOrWhiteSpace($action)) {
$action = "g"
}
if ($action -eq "g") {
Generate-Messages
}
elseif ($action -eq "c") {
Compile-Messages
}
else {
Write-Color "Error: Invalid option. Use 'g' for generate or 'c' for compile." $RED
exit 1
}
}
|