Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmedalnaqaa/jsonfpt
This project store and translate contacts json file
https://github.com/ahmedalnaqaa/jsonfpt
eloquent google-api laravel php rest-api
Last synced: about 16 hours ago
JSON representation
This project store and translate contacts json file
- Host: GitHub
- URL: https://github.com/ahmedalnaqaa/jsonfpt
- Owner: ahmedalnaqaa
- Created: 2020-02-11T00:45:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-02T11:14:21.000Z (almost 2 years ago)
- Last Synced: 2023-03-02T08:11:46.068Z (over 1 year ago)
- Topics: eloquent, google-api, laravel, php, rest-api
- Language: PHP
- Homepage:
- Size: 390 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Requirements
- php 7, apache2, mysql 5.7
- Composer
- Git## Installation
- Clone the project.
- Go to project directory and run `composer install`
- Create mysql database (ex:`json_fpt`) and configure it in the `.env` file.
- Make sure you have the right `.env` parameters configuration especially `GOOGLE_TRANSLATE_API_URL` and `GOOGLE_API_KEY`
- Run `php artisan migrate` to migrate the schema.
- Run `php artisan serve` to start the server.## Endpoints
- Get resourcesGET `api/resources` | Return resources (paginated)
- Post resourcesPOST `api/resources` | create and store resource | request body = ['file' => 'filepath', 'language' => 'languageToTranslate']
- Get resourceGET `api/resource/{id}` | get resource | `id` = the resource id
- Get resource contacts
GET `api/resource/{resource}/contacts` | get resource contacts | `resource` = the resource id
- Get contacts
GET `api/contacts` | get contacts
- Get contact
GET `api/contacts/{id}` | get contact | `id` = the contact id
## How it works
1- Go and create resource through endpoint `api/resources`, choosing contacts json file to upload and the language you want to translate.2- In Console run command `php artisan contacts:translate --limit={limit}` to loop on bulk of uploaded contacts and translate them.
```ssh
NOTE:
- We can sechdule this command to run every second for example.
```## Why that solution
* Storing and translating file at the same time is a very bad choice especially when you upload large file.
* Translating all contacts at the same time will let `Goole API` to block the request because it has a limitation in number of requests per second and the size of the text you want translate.
* This solution will provide a good performance for most of the large files because we separated uploading large files and trnaslating them in two different processes.## Postman collection for a demo
You can import this collection [https://www.getpostman.com/collections/9648a355413ebb8ed8b4] into your postman account and run a demo for the project.