Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Google Sheet as translation resource #45

Open
illuminated opened this issue Feb 12, 2023 · 1 comment
Open

[Feature request] Google Sheet as translation resource #45

illuminated opened this issue Feb 12, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@illuminated
Copy link

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 /edit while 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.

@arodriguezgb
Copy link

This would be great.

@bw-flagship bw-flagship added the enhancement New feature or request label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants