-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from beckn/add_localization
[Feature] Added localization
- Loading branch information
Showing
9 changed files
with
110 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"FULFILLMENT_STATUS_CODES":{ | ||
"order-picked-up":{ | ||
"message": "Your order has been picked up" | ||
}, | ||
"order-on-the-way": { | ||
"message": "Your order is on the way" | ||
}, | ||
"order-delivered":{ | ||
"message": "Your order has been delivered" | ||
}, | ||
"ticket-issued":{ | ||
"message": "Your ticket has been issued" | ||
}, | ||
"ticket-validated":{ | ||
"message": "Your ticket has been validated" | ||
}, | ||
"charging-started": { | ||
"message": "Your charging has started" | ||
}, | ||
"charging-stopped":{ | ||
"message": "Your charging has stopped" | ||
}, | ||
"charger-not-working":{ | ||
"message": "Hi, it looks likes your charger is not working. DO you want to find other chargin stations?" | ||
}, | ||
"charging-completed":{ | ||
"message": "Hi, your chargin is complete!" | ||
}, | ||
"checked-in": { | ||
"message": "You have succesfully checked-in to your stay!" | ||
}, | ||
"checked-out":{ | ||
"message": "You have succesfully checked-out from your stay!" | ||
} | ||
}, | ||
"ALL_MESSAGES": { | ||
"session_cleared": "Your session has been cleared! You're all set to start a new one.", | ||
"session_and_profile_cleared": "Both your session and profile have been cleared! You're ready to start fresh.", | ||
"route_selected": "Your route is all set! Here's your navigation link: ${url}. What's next on your agenda?", | ||
"request_in_progress": "Hang tight! We're currently processing your request...", | ||
"request_processed": "All done! Your request has been processed and we're getting your response ready...", | ||
"request_failed": "Oops, we hit a snag processing your request. Want to give it another shot?", | ||
"request_to_beckn_failed": "Looks like we couldn't get that request through. How about we try something different?", | ||
"incident_on_road": "Heads up: ${message}. Could you share your current location so I can find some alternative routes for you?", | ||
"formatting_failed": "We had trouble understanding that instruction.", | ||
"api_call_failed": "Oops, we ran into an issue calling the API.", | ||
"failed_to_process_instruction": "We had trouble processing that instruction.", | ||
"missing_source": "Mind sharing the starting point for your journey?", | ||
"missing_destination": "Could you let us know your destination?", | ||
"route_list_description": "Here are some route options for you. Which one do you prefer?" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, it} from 'mocha' | ||
import * as chai from 'chai' | ||
import get_text_by_key from '../../utils/language.js' | ||
const expect = chai.expect | ||
|
||
describe('test cases for language utils', ()=>{ | ||
it('Should return valid messge from language key', ()=>{ | ||
const message = get_text_by_key('session_cleared') | ||
expect(message).to.be.a('string'); | ||
}) | ||
|
||
it('Should return valid messge from language key using variable', ()=>{ | ||
let key = 'KEY_TO_MATCH' | ||
const message = get_text_by_key('route_selected', {url:key}) | ||
expect(message).to.be.a('string'); | ||
expect(message).to.contain(key); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { readFileSync } from 'fs'; | ||
const language = JSON.parse(readFileSync('./config/language.json')) | ||
|
||
|
||
function get_text_by_key(key, variables = {}, category='ALL_MESSAGES'){ | ||
let text = language[category][key] || null; | ||
if (text) { | ||
Object.keys(variables).forEach(variable => { | ||
/* eslint no-useless-escape: "off" */ | ||
text = text.replace(new RegExp(`\\$\{${variable}\}`, 'g'), variables[variable]); | ||
}); | ||
} | ||
return text; | ||
} | ||
|
||
export default get_text_by_key; |