Skip to content

Commit

Permalink
Merge branch 'feat/add-i18n-support' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuseduardomedeiros committed Oct 29, 2024
2 parents 970e1b8 + d481787 commit 34e2413
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,8 @@ export default {
updated() {
this.translateAllLinks();
},
mounted() {
window.parent.postMessage(
{
event: 'getConnectBaseURL',
},
'*',
);
window.addEventListener('message', (event) => {
const eventName = event.data && event.data.event;
if (eventName === 'setConnectBaseURL') {
this.connectBaseURL = event.data.connectBaseURL;
this.translateAllLinks();
}
});
created() {
this.listenConnect();
},
methods: {
translateAllLinks() {
Expand Down Expand Up @@ -81,13 +69,19 @@ export default {
handlerSetLanguage(language) {
this.$i18n.locale = language; // 'en', 'pt-br', 'es'
},
handlerSetConnectBaseURL(connectBaseUrl) {
this.connectBaseURL = connectBaseUrl;
this.translateAllLinks();
},
getEventHandler(eventName) {
const handlerFunctionMapper = {
setLanguage: this.handlerSetLanguage,
setConnectBaseURL: this.handlerSetConnectBaseURL,
};
const handlerParamsMapper = {
setLanguage: 'language',
setConnectBaseURL: 'connectBaseURL',
};
return {
Expand All @@ -98,6 +92,13 @@ export default {
listenConnect() {
window.parent.postMessage({ event: 'getLanguage' }, '*');
window.parent.postMessage(
{
event: 'getConnectBaseURL',
},
'*',
);
window.addEventListener('message', (ev) => {
const message = ev.data;
const { handler, dataKey } = this.getEventHandler(message?.event);
Expand Down

0 comments on commit 34e2413

Please sign in to comment.