easy_localization_loader
easy_localization_loader copied to clipboard
[Feature request] Google Sheet as translation resource
Can a Google Sheet be added as a translation resource?
The usecase and the process would be like this:
- create a Google Sheet where the first column contains keys and subsequent columns would contain language IDs
- share the sheet with everyone with a link
- extract the DocID and SheetID values: DocID would sit, in the shared URL, between
spreadsheets/d/and/editwhile the sheet ID would be the#gid=parameter from the URL when we pen the sheet in browser (if it's the first sheet, the sheet ID is -0) - we define the docID and sheetID variables
Apart from reducing complexity of sharing a translation resource, we can also use the Google's automated translation in sheets this way.
An example code (utilizing the http package) that extracts CSV from a shared Google sheet would be something like:
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
Future<void> downloadCsvFromGoogleSheet(String documentId, String sheetId) async {
// Set the API endpoint for the Google Sheets API
var endpoint = 'https://docs.google.com/spreadsheets/d/$documentId/export?format=csv&id=$documentId&gid=$sheetId';
// Send a request to the API to get the CSV data
var response = await http.get(endpoint);
// Check if the request was successful
if (response.statusCode == 200) {
// Write the response content (the CSV data) to a local file
var file = File('$sheetId.csv');
await file.writeAsString(utf8.decode(response.bodyBytes));
print('CSV data successfully saved to $sheetId.csv');
} else {
print('Request failed with status code ${response.statusCode}');
}
}
// Example usage:
void main() {
var documentId = 'your_document_id_here';
var sheetId = 'your_sheet_id_here';
downloadCsvFromGoogleSheet(documentId, sheetId);
}
I could also try to do a PR with this addition.
This would be great.