# I18n Split As Chunks Plugin

generaly we have manage our all I18n keys and values as language specific i18n files and then we download all i18n in initial page load.

### what is the problem with this?.

the problem is i18n file keep get's grown it will affect the the inital page load and critial rendering path.
So, We have decide to create a plugin for split i18n per chunk's of js vise.

### what is i18n split?

it is like code split for i18n.
we will collect i18n from js chunk and we will create separate i18n chunk per js chunk,  
 with this we already load Js chunks are on demand and now we also download i18n also ondemand with this the initial and forthere actions.  
 when js download's we will download i18n with it.

### How to we going to i18n split?

we will read the js chunk and collect I18n keys form it,  
 then we will create i18n chunk files with these used keys.

### how do you collect i18n keys from js files?

we will traverse the js file's AST (static analysis) and find i18 keys,  
 we will concider all string which is in jsResource file as i18n keys.  
 and you can tell dynamic i18n key by js comments,  
 Like Below:-

```js
fetch('tickets?view=view1').then(data => {
  // I18n support.ticketsEmpty
  // I18n support.viewNotFount
  // I18n support.permissionDenied
  let text = getI18nValue(data.i18nkey);
});
```

### is there any posiblity for unwanted keys in some chunk?

Yes, there is two posiblity

1. js comment , if you write js comment but it is not needed then it will be add into i18n chunk  
   `To Resolve` we currently do not have perfect idea for this, But we can check this by chunk size limit.  
   `idea's will be welcome`
2. like we said "we will concider all string which is in jsResource file as i18n keys",  
   So if you use string not for i18n but it was in jsResource then it will be add into i18n chunk.  
   `To Resolve` this problem we can use some kinda prefix or something.

### how do we downlowd and give to app?

we have over write defualt webpack requireEnsure (every dynamic chunk requests are done by that function) function.  
 and we parlarly dowload i18n files. and we ask jsonFunction, to our plugin.  
So we send i18nkeys , when it was download,  
you must store all i18n keys, we give asycrnsly by that function download in that patticular.  
so you must store and update (like append or assign) everytime that function call.

### how to use this feature?

to use this feature use have give the below oprtions  
 `package.json`

```json
{
  /// ...some things
  "react-cli": {
    //  ...some things
    "i18n": {
      "chunkSplitEnable": true,
      "jsResource": "./deskapp/properties/JSResources.properties",
      "localeVarName": "window.userInfo.langCode",
      "jsonpFunc": "window.loadI18nChunk",
      "templateLabel": "{{--user-locale}}", // this is  for html template i18n file path locate template
      "propertiesFolder": "./deskapp/properties"
    }
    //  ...some things
  }
}
```

<!-- not need below -->
<!--we have added new feature for css to write logic to how hover related css work in hoverhover and a

### is there any problems with static analysis?
  Yes,

### how do we use dynamic i18n key?

  and we will download i18n file with

  and when js chunk download's then we will download i18n as need.
  we all know in our app we loading i18n as one single big file for each locale(language).
  we are going to split i18n as per js chunk, and when js chunk download's then we will download i18n as need.


  -->
