Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
angulardart 多语言生成脚本
function Get-Files($path, $extension ) {
$result = [string](Get-ChildItem -Path $path -Recurse -Filter $extension | Resolve-Path -Relative)
return $result + " ";
}
function Get-DartFiles ($project) {
$path1 = Get-Files "lib" "*.dart"
$path2 = Get-Files ".dart_tool\build\generated\$project\lib\" "*.dart"
$path3 = $path1 + $path2;
return $path3
}
function Get-ArbFiles($dir) {
$result = Get-Files $dir "*.arb"
return $result + " ";
}
function Get-SupportCultures {
return "en_US", "zh_CN"
}
function Extract_To_Arb ($project, $outputDir) {
If (!(test-path $outputDir)) {
New-Item -ItemType Directory -Force -Path $outputDir
}
$path = Get-DartFiles($project)
Get-SupportCultures | ForEach-Object {
$cmd = "pub run intl_translation:extract_to_arb --locale $_ --output-file $_.arb --output-dir $outputDir $path"
Invoke-Expression $cmd
}
# Invoke-Expression ("pub run intl_translation:extract_to_arb --locale zh_CN --output-file zh_CN.arb --output-dir messages " + $path )
}
function Generate_From_Arb ($project, $arbDir, $codeDir) {
If (!(test-path $codeDir)) {
New-Item -ItemType Directory -Force -Path $codeDir
}
$dart_files = Get-DartFiles($project)
$arb_files = Get-ArbFiles($arbDir)
$cmd = " pub run intl_translation:generate_from_arb --output-dir $codeDir $arb_files $dart_files"
Invoke-Expression $cmd
# pub run intl_translation:generate_from_arb --output-dir lib/messages messages/intl_messages.arb lib/app_component.dart .dart_tool/build/generated/examples.i18n/lib/app_component.template.dart
}
$choice = Read-Host("
Choice 0 to extract_to_arb
Choice 1 to generate_from_arb
");
$proj = (Get-Content .\pubspec.yaml)[0].Replace("name:", "").Trim()
$arbDir = "i18n"
$codeDir = "lib/i18n"
if ($choice.Equals("0")) {
Extract_To_Arb $proj $arbDir
}
else {
Generate_From_Arb $proj $arbDir $codeDir;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.