-
Notifications
You must be signed in to change notification settings - Fork 30
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
not a function #2
Comments
Hi, |
I included it after first import because this import sets globals and other stuff. |
😞 |
Is simple
In the html
That's all!! 👍 |
@alejonext thanks for finding this. I wonder why the L function is not available in angular if we make it global and also available in resources. I'll amend the readme with this instructions :) Thanks again! |
Hi everyone, I've tried to use the solution from @alejonext , but I did not manage. MY_PROJECT/utils/i18n.ts
MY_PROJECT/main.ts
MY_PROJECT/components/explorer/explorer.ts
MY_PROJECT/components/explorer/explorer.html
|
Well, I had some other issues regarding NativeScript and Angular2 so I decided not to go with Angular2 at this moment and I have no issues with this plugin when used without Angular2. |
Just found old version of my project when I was using Angular2 so I will try suggested solution on my project. |
@loloof64 stupid question: did you import the @alejonext branch? Thanks :) |
Not a stupid question, as it appears that I did not know there is the @alejonext branch. |
Oh : just found #6. |
I think you have 2 ways:
:) |
Thanks I'll try it right now 😃 |
Sorry, but I am trying to solve npm depencies issues. Later I will have to go, but as soon as I come back, I'll try again. |
I found a way how to make this work (I'm using original nativescript-i18n plugin) Key is to make custom Angular2 Pipe and make it global so you can use it in any template. In main.ts after adding:
add this: `import {provide, PLATFORM_PIPES} from '@angular/core'; @pipe({name: 'i18n'}) To make this pipe available globally we must use it in bootstrapping application, so add this in main.ts nativeScriptBootstrap:
After that, in you template file you can use this pipe like this:
|
@AirMike could you provide a test case project I could play with? Tbh, this angular stuff (all the pipes and transforms) you have to do to make it work looks to me like being against any purpose of a plugin. It should work out if the box with minimal changes to the code :( Thanks for your help 😸 |
Edit. Regards |
The code in the branch, works in typescript in Angular2 and the code in this issuse is in ES6. The documentation (3 mouths ago) typescript and Angular2, thas code in the branch in funciontal. And construct the App is this main.ts require('globals');
// Use alejonext/nativescript-i18n
import i18n form 'nativescript-i18n/angular';
// Or
import i18n form './util/i18n';
// More Code
nativeScriptBootstrap(AppComponent, [
provide(PLATFORM_PIPES, {
useValue: [i18n],
multi: true
})
]); The file
|
I can definitely confirm that the translation works with the steps given by @AirMike . I tested it with the french locale in the emulator settings. Just one line I've added for android not to complain about reflect-metada
just below
Here is my project,with which you can play if you want. (Support for english and french). Just two things I did not test
(@alejonext : I've tried with the steps from @AirMike , which seems to be inspired by your pull request). |
I can confirm that @alejonext branche is working but only if I add generated angular.js file to the repository (see my forked repository - link bellow). Also I have suggestion to tweak it a little bit so it will look nicer when used. If we add one more import in angular.ts file at the top:
and then at the bottom add export (in the same angular.ts file):
Then when plugin is installed you can import it like this (main.ts file - please note /angular part in the import):
Then in the nativeScriptBootstrap just add this:
You can see suggested changes in angular.ts file here and generated angular.js file here and try using this fork: https://github.com/AirMike/nativescript-i18n ( @loloof64 : you can always manually delete folders hooks and node_modules and than just do |
@AirMike thank you. I did not know about |
@AirMike @loloof64 thank you so much for testing and finding a fix for this I have few questions 😄
Thanks again 😸 |
I will make i change with function name and if everything work make a PR. Regarding decorate definition: this is something that is automatically generated by TypeScript meaning that all coding is done in ts file and TypeScript then generates js file as it see it. |
@AirMike ok, I think I can live with a ts file in the plugin :) |
Yes, maybe something can be improved in the pipe.
but it did not work either. |
I think you need to do it in angular.js too ? |
|
It works ! What are the steps for a Pull Request : I must first clone your repository and launch a PR : right ? |
Amazing :) For the PR this should do it:
😄 |
Thanks 😄 I do it right now. |
Done PR 😄 |
After I merge the PR and update npm you can test it just like any other dev 😸 |
Yes. That's right, anybody will be able to notify a problem about the new version. 😄 |
The point is that I want to push the changes so you can test with the real thing :) |
No problem 😄 I'll test it as soon as you released it 😄 |
I added a comment on the PR |
I've updated the README on my PR with a detailed use case 😄 |
Merged, bumped and published to npm 🎉 Thanks again 😄 |
You're welcome 😄 I've just tested the plugin using the normal installation sequence, and it works like before : as expected 😄 |
Yay 🙌🙌🙌🙌 Sent from my iPhone
|
👍 😋 |
Hello again. I've just noticed that, in TypeScript code, one has just to invoke I can update my version of the repository with Regards. |
Hi, sorry for the late reply. |
No, as well as I setup app.ts with I18N_PROVIDER (like noticed in the readme, so the end-user should already have done this), the L function is available by calling global.L (without trailing s) in any typescript file (except the launcher app.ts of course). As simple as that. So L function can also be used in code-behind in TypeScript without further configuration 😄 |
@loloof64 But do you load globals in app.ts ? The equivalent of |
No I just have to import the I18N_PROVIDERS, because when I do it, it always import the globals. And if I set it in the bootsrap providers (main application), then it will be available anywhere. |
but not app.ts right? or I'm not understanding the issue? 😆 |
It's not an issue, it's just a notice that the L function can also be used in TypeScript code, but we don't have to call |
Mmm, ideally should be the same. I'll try to take a look when I'll have a little time Sent from my iPhone
|
I am trying to localize an alert message inside a typescript function in a ...component.ts file. In 'app.module.ts' of our app I have:
But when I try something like alert(L('orderform_add_error_no_sku')); in the ...component.ts the build says it cannot fine name 'L'. What am I forgetting to do? EDIT |
@ivoeersels I think it's related to #33 |
@rborn I am not so sure about it... in issue #33 I mention that the code doesn't even build because NPM not downloading and installing 'angular.ts'. So at that moment nothing worked. After downloading it manually it works but only in the templates, not in the TypeScript component .ts files and that is what I mentioned here. |
@ivoeersels to be honest this is over my head 😢 I don't use typescript and neither angular. |
Hi, I'm trying to use this package with ns-angular2.
I included
require('nativescript-i18n');
after
import {nativeScriptBootstrap} from "nativescript-angular/application";
in main.ts file and later when I use translation in xml file
<Button text="{{ L('Login') }}"></Button>
I get error:
The text was updated successfully, but these errors were encountered: