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 a cache option to the constructor. #5

Open
bgaillard opened this issue Aug 23, 2015 · 0 comments
Open

Add a cache option to the constructor. #5

bgaillard opened this issue Aug 23, 2015 · 0 comments
Assignees
Milestone

Comments

@bgaillard
Copy link
Member

For now the library cache translations using a plain Javascript object (i.e in memory), it works but it can be problematic with large translation files.

We could add a cache option transmitted to the Polyglot constructor. If this cache option is a string it allows to use a pre-defined cacheManager, if this cache option is a function it defined a custom cacheManager.

Pre-defined cache managers could be :

  • MEMORY : Cache translations using a plain Javascript object
  • LOCAL_STORAGE : Cache translations using the Local Storage
  • SESSION_STORAGE : Cache translations using the Session Storage
  • INDEXED_DB : Cache translations using IndexedDb
  • WEB_SQL : Cache translations using Web SQL

Each pre-defined cache manager could also be configured using a Javascript object, for example.

var polyglot = new Polyglot(
    {
        cache : {
            type : 'LOCAL_STORAGE', 
            params : {
                key : 'myproject.i18n'
            }
        }
    }
);

Sample custom cache manager

var polyglot = new Polyglot(
    {
        cache : function(type, locale, version, data) {
            ...
        }
    }
);
@bgaillard bgaillard added this to the 1.0.0 milestone Aug 23, 2015
@bgaillard bgaillard self-assigned this Aug 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant