Bump version to 0.5.1 and update localization files; update dependencies in requirements and pyproject.toml
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good
All checks were successful
Gitea/kapitanbooru-uploader/pipeline/head This commit looks good
This commit is contained in:
99
update_translations.ps1
Normal file
99
update_translations.ps1
Normal file
@@ -0,0 +1,99 @@
|
||||
# update_translations.ps1
|
||||
param(
|
||||
[string]$ProjectDir = "kapitanbooru_uploader"
|
||||
)
|
||||
|
||||
# 1. Ensure project directory exists
|
||||
if (-not (Test-Path $ProjectDir)) {
|
||||
Write-Host "Error: Project directory '$ProjectDir' not found." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 2. Extract metadata from pyproject.toml
|
||||
$pyprojectPath = Join-Path -Path $PSScriptRoot -ChildPath "pyproject.toml"
|
||||
$pyprojectContent = Get-Content $pyprojectPath -Raw
|
||||
|
||||
# Extract version
|
||||
$version = [regex]::Match($pyprojectContent, 'version\s*=\s*"([^"]+)"').Groups[1].Value
|
||||
|
||||
# Extract author information
|
||||
$authorMatch = [regex]::Match(
|
||||
$pyprojectContent,
|
||||
'(?s)name\s*=\s*"([^"]+)".*?email\s*=\s*"([^"]+)"'
|
||||
)
|
||||
$authorName = $authorMatch.Groups[1].Value.Trim()
|
||||
$authorEmail = $authorMatch.Groups[2].Value.Trim()
|
||||
|
||||
# Extract project description
|
||||
$description = [regex]::Match($pyprojectContent, 'description\s*=\s*"([^"]+)"').Groups[1].Value
|
||||
$currentYear = Get-Date -Format "yyyy"
|
||||
|
||||
Write-Host "Detected version: $version" -ForegroundColor Cyan
|
||||
|
||||
# 3. Navigate to project directory (absolute path)
|
||||
Push-Location (Resolve-Path $ProjectDir)
|
||||
|
||||
try {
|
||||
# 4. Ensure locales directory exists (absolute path)
|
||||
$localesDir = Join-Path -Path $pwd -ChildPath "locales"
|
||||
if (-not (Test-Path $localesDir)) {
|
||||
New-Item -Path $localesDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# 5. Define absolute path for .pot file
|
||||
$potFile = Join-Path -Path $localesDir -ChildPath "messages.pot"
|
||||
if (Test-Path $potFile) {
|
||||
Remove-Item $potFile -Force
|
||||
}
|
||||
|
||||
# 6. Collect .py files with absolute paths
|
||||
$pyFiles = Get-ChildItem -Filter "*.py" -File | ForEach-Object { [System.IO.Path]::GetRelativePath($pwd.ProviderPath, $_.FullName) }
|
||||
|
||||
# 7. Generate .pot file
|
||||
xgettext `
|
||||
--package-name="Kapitanbooru Uploader" `
|
||||
--package-version="$version" `
|
||||
--copyright-holder="$authorName" `
|
||||
--msgid-bugs-address="$authorEmail" `
|
||||
--add-location `
|
||||
-d messages `
|
||||
-o $potFile `
|
||||
$pyFiles
|
||||
|
||||
if (-not (Test-Path $potFile)) {
|
||||
Write-Host "Error: .pot file generation failed." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 8. Update .pot header with absolute path safety
|
||||
$potContent = Get-Content $potFile -Raw
|
||||
$updatedContent = $potContent `
|
||||
-replace 'SOME DESCRIPTIVE TITLE', $description `
|
||||
-replace 'YEAR THE PACKAGE''S COPYRIGHT HOLDER', "$currentYear $authorName" `
|
||||
-replace 'FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.', "$authorName <$authorEmail>, $currentYear." `
|
||||
-replace 'LANGUAGE <LL@li.org>', "Polish <$authorEmail>" `
|
||||
-replace '"Language: \\n"', '"Language: en\\n"' `
|
||||
-replace ', fuzzy', ''
|
||||
|
||||
# 9. Write back using absolute path
|
||||
[System.IO.File]::WriteAllText($potFile, $updatedContent.Trim())
|
||||
|
||||
# 10. Update .po files
|
||||
$poFiles = Get-ChildItem -Path $localesDir -Filter "messages.po" -Recurse -File
|
||||
foreach ($poFile in $poFiles) {
|
||||
Write-Host "Updating: $($poFile.FullName)" -ForegroundColor Yellow
|
||||
msgmerge --update --backup=none $poFile.FullName $potFile
|
||||
# Force Project-Id-Version update
|
||||
$content = Get-Content $poFile.FullName -Raw
|
||||
$updatedContent = $content -replace(
|
||||
'(?s)(msgstr ""\s+"Project-Id-Version: ).*?(\\n")',
|
||||
"`$1Kapitanbooru Uploader $version`$2"
|
||||
)
|
||||
[System.IO.File]::WriteAllText($poFile.FullName, $updatedContent.Trim())
|
||||
}
|
||||
|
||||
Write-Host "Done." -ForegroundColor Green
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
Reference in New Issue
Block a user