Coder Social home page Coder Social logo

getx_google_sheets_translation_code_generator's Introduction

GetX Google Sheets Translation Code Generator

When handling localization for my app I was using the excellent https://pub.dev/packages/flutter_sheet_localization package. I have also been using the GetX package. GetX now has their own translation code options so I wanted the benefits of storing my translations in google sheets but also wanted the ability to have the code I would need for GetX generated automatically since you must write a lot of tedious code to translate your app.

I created a code generator that will do this.

So let me explain how it works. You need to create a translation for your app in google sheets.

You can copy my sheet as a starting point for your own app. The cool thing about using a google sheet is you can have google translate a field with a simple google formula: =GOOGLETRANSLATE(B4,en,fr) This says translate the phrase in field B4 from english to french. Next you can edit the main.dart file in the project I listed earlier and edit these two lines.

//the document id for your google sheet  
String documentId = "1oS7iJ6ocrZBA53SxRfKF0CG9HAaXeKtzvsTBhgG4Zzk";  //the sheet id of your google sheet  
String sheetId = "0";

The next step is to go to the command line and change to the lib/ directory. Then type:

dart main.dart

This will create a localization.g.dart file with your generated code that looks like this.

You can then use these translations in your own project with something like this.

Text('settings.updateProfile'.tr)

You can find out more about how to use getX translations here.

Anyway I hope you will find this useful for your own projects. If you would like to see how I used this in a project you can take a look at my getX flutter starter project

getx_google_sheets_translation_code_generator's People

Contributors

delay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

getx_google_sheets_translation_code_generator's Issues

Nothing written to generated file

First, thanks for your Medium article and for this code generator!

I tried it and there is nothing in the localization.g.dart file. I uncommented line 37

print('Google sheet csv:\n ${response.body}');

and it seems to be printing an html file, not csv.

I also added a print statement inside the for (var r = 1; r < fields.length; r++) {
loop and it doesn't print anything.

Did something change in the way Google sheets downloads a .csv file?

Thanks,

Jim

Using just the ID it does not work

Test your code and with the id provided in the main.dart it works,
copying the file and using the other generated id it does not work...

I find a way to solve this.
If you publish the file to the web it is possible to select the output format and the sheet, it generates then the correct url to put in the main.dart file.

Esample:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.