Hi, I find it quite handy to create language files from a google spreadsheet
- You can copy&paste the field list from the model and quickly replace quotation marks and commas
- You can use google translate (=GOOGLETRANSLATE(A1;'EN';'DE'))
- You can sort everything later, so it is easier to have a look into it later and avoid dublicates
Therefore I create a spreadsheet with 3 columns:
A: variable/expression
B: translated text / string
C: comment (explanation for later translations to other languages; if needed)
After that I use this Google Script:
Code:
function createLanguageFile() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('data');
var aLast = sheet.getDataRange().getNumRows();
var data = sheet.getRange("A1:C"+ aLast).getValues();
var content;
content = "<?php \n return [ ";
data.forEach (function (row) {
content = content + "'"+row[0]+"' => '"+row[1]+"',";
if(row[2] != ""){content = content +" //"+row[2]}
content = content +" \n"
})
content = content + "''=>'' \n";
content = content + "];"
var fileName;
fileName = "language" + new Date() + '.php';
var newFile;
newFile = DriveApp.createFile(fileName,content)
}
If you want it a bit more comfortable you can add the script to the spreadsheets navigation bar with a second script:
Code:
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Create-File')
.addItem('Create', 'createLanguageFile')
.addToUi();
}
The script creates a new file which you should find in your Google Drive base folder.
Let me know if you like it too ;-)