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

Return fullpath when key not found #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mweibel
Copy link

@mweibel mweibel commented Mar 21, 2016

When using a key which is not found, IMHO we should return the full path instead of just the last part of the iteration. This makes it possible to use a fallback if the passed key is the same as the returned key.

Though: I guess you had a reason why you returned just the last key. Should we maybe instead add an optional fallback argument?

When using a key which is not found, IMHO we should return the full path instead of just the last part of the iteration. This makes it possible to use a fallback if the passed key is the same as the returned key.
@alexkuz
Copy link
Owner

alexkuz commented Mar 21, 2016

It's just so the page wouldn't seem messy if langpack value is not defined yet (or langpack was not loaded or something).
I think it's better to have an optional notFoundCallback, by default - (locale, path) => path[path.length - 1]. I guess i18n should be a factory that receives options argument:

const DEFAULT_OPTIONS = {
  notFoundCallback: ...
};

export default function i18n(options) {
  options = { ...DEFAULT_OPTIONS, ...options };

  return (state = DEFAULT_STATE, action) => {
    return (action.type === LOAD_LANG_SUCCESS) ?
      mergeLang(state, action, options) :
      state;
  }
}

and then pass it to i18nResolver, something like that.

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