tflori / angular-translator

translation module for angular
https://tflori.github.io/angular-translator/
MIT License
21 stars 6 forks source link

Add support for nested objects in default TranslateLoader #4

Closed BorntraegerMarc closed 7 years ago

BorntraegerMarc commented 7 years ago

Hi guys So I saw that nested objects are currently not supported in the default translate loader. This line disables it: https://github.com/tflori/angular2-translator/blob/master/angular2-translator/TranslateLoaderJson.ts#L48

Maybe including support for nested objects in the default translate loader would be a good idea? So something like this would be possible: translate.translate("app.loginText")

cheers

tflori commented 7 years ago

Hi Marc, it should already be possible by defining it as key:

{
  "app.loginText": "Please log in before continuing!"
}

But you are right may be some one want this. It needs some more work (recursive searches for translation). If you want you can create a PR for it. Otherwise it will need some time till I developed it.

BorntraegerMarc commented 7 years ago

Yeah, I ment something like:

{
  "app": {
    "loginText": "Login"
  }
}

Will try to open up a PR.

tflori commented 7 years ago

Hey, good news: I couldn't stop thinking of it and found an easy solution

tflori commented 7 years ago

I create the PR #5 . if this is ok for you I can create version 1.3. or you see another problem here?

BorntraegerMarc commented 7 years ago

I couldn't stop thinking as well and opened another PR :) Maybe we could combine them?

BorntraegerMarc commented 7 years ago

I checked out your PR @tflori and missed the the test that the return string needs to have dots included...

tflori commented 7 years ago

You missing a test? What test? In lines 184 and 185 in TranslateLoaderJson.spec.ts i'm testing that a dot is included in the translation key

BorntraegerMarc commented 7 years ago

yeah, I ment, that I am missing the test in my code... So I'm gonna add it now. The new PR is up soon.

tflori commented 7 years ago

@BorntraegerMarc npm update thanks for your contribution :smile: