
隨著企業系統架構越來越複雜,為解決開發過程中,不同角色或應用程式,需要維護同一份語系翻譯檔。
透過 Google sheet 機制就可以達到多人同時維護一份翻譯檔,並透過匯出 csv 檔的功能,將檔案下載到本地,透過 Powershell 去讀取 csv,轉換成 i18n Json 物件並匯出。
建立一個新的 google sheet
https://docs.google.com/spreadsheets/d/192ji-2k1XHOdXYBu8fD7wNSAnz-eKcdQB57LR66quTg
開啟 google sheet 允 許知道連結的人擁有訪問存取權限

$filepath = './Rawi18nFile.csv'
& { 
 (new-object net.webclient).downloadfile('https://docs.google.com/spreadsheets/d/192ji-2k1XHOdXYBu8fD7wNSAnz-eKcdQB57LR66quTg/export?format=csv', $filepath)
}
$translate = @{}
$NewCsvData= Import-CSV $filepath  | Foreach-Object{       
   
    foreach ($property in $_.PSObject.Properties)
    {
        if($property.Name  -eq 'Module' )
        {
            $module =   $property.Value
            continue
        }
        
        if($property.Name -eq 'Key')
        {       
            $key =  $property.Value
            continue
        }       
                
        $mainKey ="$module.$key";
            
        if (!$translate.ContainsKey($property.Name)) {          
            $translate[$property.Name]= @{}         
        }   
    
         $translate[$property.Name][$mainKey]  = $property.Value                    
    }           
}
forEach($lang in $translate.Keys){    
    $translate[$lang] | ConvertTo-Json  | % { [System.Text.RegularExpressions.Regex]::Unescape($_) } | new-item -force  "./output/$lang.json"  
}
右鍵 > 用 Powershell 執行

Powershell 顯示成功

此時 output 資料夾產生 i18n語系檔


