Mark Ku's Blog

Using PowerShell to download Google Sheets and generate i18n JSON files

Problem

As enterprise architectures grow more complex, different roles and applications often need to maintain the same set of translation files during development.

How it works

Google Sheets gives you collaborative editing for free. By exporting the sheet as CSV and downloading it locally, PowerShell can read the CSV, transform it into i18n JSON objects, and write them out.

First, use Google Sheets to enable collaboration

  1. Create a new Google Sheet
    https://docs.google.com/spreadsheets/d/192ji-2k1XHOdXYBu8fD7wNSAnz-eKcdQB57LR66quTg

  2. Set the share permissions so that anyone with the link can access it Google Sheet with sharing dialog showing anyone with link access

Write the PowerShell script

$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"  
}

Result

  1. Right-click > Run with PowerShell Windows right-click menu showing 'Run with PowerShell' option

  2. PowerShell reports success PowerShell window listing generated i18n JSON files

  3. The i18n locale files appear in the output folder Notepad++ displaying a Korean i18n JSON file with error messages

Author

Mark Ku

10 年以上的軟體工程師,做過北美電商與 AI SaaS 訂閱收費系統。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

The author's company

Vibe Coding architecture & coaching

Built internal tools with AI but afraid nobody can fix or change them safely? 226 Network helps you put the code in Git, keep secrets out of it, move schedules onto a stable host, and add handover docs and tests.

Popular Posts

View all
Mark Ku
··637

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··472

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··268

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··215

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··210

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··209

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11