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

Add lang keys #45

Closed
wants to merge 4 commits into from
Closed

Add lang keys #45

wants to merge 4 commits into from

Conversation

mauthi
Copy link
Contributor

@mauthi mauthi commented Mar 19, 2018

No description provided.

@mauthi
Copy link
Contributor Author

mauthi commented Mar 19, 2018

maybe you can help me with quality review because the things are not so clear for me :(

Copy link
Member

@aocneanu aocneanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented inline

@@ -15,7 +15,19 @@ export const getters = {
}

const { lang } = rootState.user.preferences.global;
return state.i18n[lang] ? (state.i18n[lang][key] || key) : key;
const { env } = rootState.meta;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the env const only when the if fails, so after the if

const { env } = rootState.meta;
if (state.i18n[lang] && state.i18n[lang][key] !== undefined) {
return (state.i18n[lang][key] || key);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the else is redundant because if the condition is true we return a value and we don't go past line 20. If the condition is false then we go to 21 with or without else.

// not needed
}).catch((error) => {
// not needed
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really an anti-pattern for vuex to make ajax calls from a getter. The getters should be responsible only with computing the state. To keep the convenience, we will go with this for now, but maybe in the future we can think of a better solution. Right now I can't find any other suggestion.

Let's do

if (env === 'local') { 
   axios.patch("/api/system/localisation/addLangKey", { langKey: key });
}

return key;

@mauthi
Copy link
Contributor Author

mauthi commented Mar 20, 2018

will do the changes

@aocneanu
Copy link
Member

There is still something else that I see as a problem.. when the request for adding a new key is made, the state is not changed. If we navigate to a diff page (without hitting refresh), and then come back, the request(s) will be made again and again.

@mauthi
Copy link
Contributor Author

mauthi commented Mar 20, 2018 via email

@aocneanu
Copy link
Member

do we have the same problem if we change a translation in frontend?

We have in the sense that the state is not updated.

maybe we should add an mechanism to update state after changing something? do you have an idea for this?

We should, and this mechanism should work also for role permissions update

@mauthi
Copy link
Contributor Author

mauthi commented Mar 20, 2018 via email

@aocneanu
Copy link
Member

not really.

If we navigate to a diff page (without hitting refresh), and then come back, the request(s) will be made again and again.

this will happen only after the new implementation.

@mauthi
Copy link
Contributor Author

mauthi commented Mar 20, 2018 via email

@aocneanu
Copy link
Member

I'm trying something and I'll get back on this.

@aocneanu
Copy link
Member

@mauthi for the FE we have now everything prepared for adding missing keys.

I also updated the locale store to accept a new addKey mutation that will resolve the problem of unwanted requests.

@mauthi
Copy link
Contributor Author

mauthi commented Mar 20, 2018

can you explain this to me in more detail - or what do I have to do now?

@aocneanu
Copy link
Member

We need to get the backend working with the new feature (in the localisation repo), and then uncomment this line https://github.com/laravel-enso/Core/blob/master/src/resources/assets/js/modules/enso/plugins/__.js#L8.

I refactored the locale module to work with the new global helper __.

We can close this PR.

@aocneanu aocneanu closed this Mar 20, 2018
@mauthi
Copy link
Contributor Author

mauthi commented Mar 20, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants