Which plugin (npm) to use for localization in NativeScript? - nativescript

Which plugin (npm) to use for localization in NativeScript and Angular?

nativescript-localize implements the native way of localizing iOS / Android apps.
tns plugin add nativescript-localize
If you like to find any plugins, you can simply do a search at https://market.nativescript.org/ Checkout the number downloads / recent releases to understand the popularity / stability of the plugin.
Note: At present this plugin doesn't support switching the language within your app, it always picks up the default language of the device which is more generic way of handling localization with mobile apps.
If you prefer to control the language selection within your app, you may have to go with any angular specific plugins to manage your language.

You can simply use ngx-translate for you NativeScript project. All other plugins implements native i18n, so you can't change the application language on runtime. Because they depend on the os language.
Most of the time we use English as our os language but doesn't necessarily mean our native language is English. Here you go.

Related

Cannot add Judopay to Xamarin forms project

I am trying to include Judopay in my project, and I was able to add it to Android and iOS, but not to the Xamarin forms project. There is no NuGet to be included and I can't seem to add the component reference. Any idea on how can I add it? I cannot use any of these:
using JudoDotNetXamarin;
using JudoPayDotNet.Enums;
using JudoPayDotNet.Models;
Again, they only work on iOS or Android, but not Xam forms.
That is because they only provide platform implementations. You will need to tell your Forms app which implementation to use at what time.
The correct way to go about this is with some form of IoC, using dependency injection or service location. Luckily Xamarin Forms has this integrated:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/
Using the references from the Android or iOS projects in your shared code will likely not work completely or break things. Maybe not immediately but surely later on. (Except when there really is no platform-specific functionality, then you might get away with this.)

how to ensure backward-compatibilty in a xamarin forms application?

How do i make sure my app can run on android devices below Lollipop( version 4.03 to 4.42). I watched a xamarin university video that says xamarin forms supports android version 4.03(ice-cream sandwich) and upwards. I also read about runtime checks and feel like this might be the answer to my problem, but how can i write runtime checks for android when basically all my ui and logic is contained in the PCL project?
The first thing to do is ensure you are using the Android AppCompat library. I think new projects use this by default now. If you have an older project that doesn't follow these instructions to update. This will allow your app including any Material Design look and feel to run on older versions of Android.
If you do things differently based on Android version, put the code for this in the Android project and use dependency service to call it.
Like this:
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
// level specific code here
}

Import ReactNative libraries into a NativeScript application

I have some Android development experience along with React.js. I'm working on a new mobile project and I haven't been sold entirely on either framework yet.
I'm thinking about using the NativeScript framework for its maturity and because it has more libraries with the functionality that I need but I'd like to design my views in a manner similar to ReactJS. I know I could write my own modules for ReactNative but that would require then I'd have to write modules for both Android and iOS. I'd like to avoid that if I could.
I was thinking about importing the necessary ReactNative libraries into a NativeScript project and then being able to write views in a way similar to ReactNative but still using NativeScript.
Is this doable?
Not sure about your exact question. I did just see an integration between Preact and NativeScript you may be interested in. Take a look here: https://github.com/staydecent/nativescript-preact
I believe that repo is in the early stages, but if enough people want something similar, it'll get worked on faster.
Using React Native in NativeScript is not the right approach, either of it are not built to work together and wouldn't work due to architectural reasons. Here is an NativeScript official comparison of these two.
Both are built for solving same problem (building native apps using JS, without webview hybrid app approach) by trans-compiling XML based view layer(which both these framework has its own syntax and so cant be shared) to build Native UI.
Said that view layer has its own syntax for both and cant be shared, model and controller layer cant be shared as well, due to the fact that NativeScript has few things packed as part of the application package, like JavaScript runtime, c++ and Java API layer which helps in exposing all the Native API without the need for any explicit native API wrapper we have in ReactNative.
React Native have platform specific UI components as well as hardware capabilities, which is not the case with NativeScript. Offcouse, that comes with the cost of a fatter app package size(50+MB) compared to <10MB for ReactNative. More on ReactNative vs NativeScript comparison here.

Using the Nativescript platform-specific project

To my understanding, Nativescript takes the javascript (or typescript) + nativescript code and creates project files for both android and ios in order to be able to run them as native apps. I also know that these files all seem to be located in the Resources directory. However when I try to run a simulator from the xcode project that is created, it fails.
I don't want to know how to fix the simulator failure, I just want to know if it's possible for a swift developer to take the xcode project created by Nativescript and continue developing as a regular native app.
If so, is this possible with the android project as well?
Please check this out
https://www.nativescript.org/blog/using-nativescript-in-an-existing-native-ios-android-applications
The two articles explain in detail how you can embed the NativeScript runtimes in native Objective-C and Android applications.

Using HttpClient in a Xamarin core project

I am doing a project for multiple platforms where I have followed best practices and created a core project to contain all the code that is the same on all platforms.
To do the network communication I would like to use HttpClient which seems to be the recommended approach for communicating with web services going forward.
I am NOT doing a PCL but just a standard C# library to contain the core project. However it seems that there is no common implementation of HttpClient but only platform specific ones. I cannot reference and use it in my core but only in my Android and iOS projects.
I would very much prefer to have all networking code in my core project and as I see it there are two options - neither of which I like.
Make a common interface that I can use in the core project that is implemented as a wrapper on both Android and iOS.
Use another technology that is supported in the core project - I am thinking webclient or the like.
What is the recommended approach and why hasn't Xamarin made HttpClient available as a common library?
Hope someone can help,
Thanks
I recommend checking out ModernHttpClient https://github.com/paulcbetts/modernhttpclient
It is a cross-platform networking library for iOS and Android. From the project:
This library brings the latest platform-specific networking libraries
to Xamarin applications via a custom HttpClient handler. Write your
app using System.Net.Http, but drop this library in and it will go
drastically faster.
You should be able to use System.Net.Http in your core library just fine, I've done it recently.
Make sure your core library is a .Net 4.5 project. There is a setting in project options for selecting the .Net version. After checking this, all you should have to do is reference System.Net.Http.dll.
If that doesn't solve your issue, are you on Windows or Mac(Xamarin Studio)?
I'm afraid you can't use HttpClient on Mono at the moment due to licensing restrictions. There is a UserVoice suggestion that you can vote on if you like.

Resources