Internationalization in vuejs, vue cli, spa

Multi language support in vuejs application can easily achieved by using the vuei18n plugin.
All you need to do is just  follow below steps.
My base app is created using vue cli you can





check the details here how to create vue cli app Vue CLI

Step 1:
Include the vue18n plugin in your package.json file dependencies section
"vue-i18n": "8.4.0"
next step is yarn/npm install of the same to your project.

Step 2: Create a resources.ts file in src folder.

export const resources = {
    en : {
        company_name: 'JuggerNaut',
    },
    ml : {
        company_name: 'ജഗ്ഗർനട്ട്',
    },
    cn : {
        company_name: '剑圣',
    },
};

Step 3:

Now in main.ts add the reference for resource and vue-18n libraray

import VueI18n from 'vue-i18n';
import {resources} from '@/i18n/resources';
Vue.use(VueI18n);
const i18n = new VueI18n({
  locale: 'en', // set locale
  messages: resources, // set locale messages
});

I have added the default language as 'en'
Now include it in the Vue instance creation part like below
new Vue({
  router,
  i18n,
  render: (h) => h(App),
}).$mount('#app');

Step 4:
That's it the configuration part is done now we can go to the components and use it.

I am biding the company name inside my html. this can be converted like below using resource file.

<li><a href="#">{{$t('company_name')}}</a></li>

If you want to use inside your component you can use it like below.

const companyName = this.$t('company_name') as string;

And if you want to change the language dynamically just set like below in your component

this.$i18n.locale = 'ml';

It will convert to that corresponding language.

Dependency Injection in vuejs, Vue Cli Single Page Application


We can use DI in vuejs application by very simple way, using the @Provide and @Inject property decorator.So here is the scenario you have a service and you need the instance of the same in different component in normal way you have to create the instance of the same in different components and use it there.

But using DI you can use the @Provide property decorator and declare it in your App.vue and then you can reuse it in the components wherever you want by using the @Inject property decorator

In App.vue

    import {Component, Provide, Vue} from 'vue-property-decorator';
    @Component({
    })
    export default class App extends Vue {
           @Provide('vueApiServices')
           public vueApiServices = new VueApiServices();
     }
In your corresponding component

import { Vue, Prop, Component, Inject } from 'vue-property-decorator';
import {VueApiServices} from '../../services/VueApiServices';
@Component({
    components: {},
})
export default class InventoryDetailsComponent extends Vue {

@Inject('vueApiServices')
private vueApiService!: VueApiServices;
}



Swagger UI Integration to .Net core Web API in 4 Steps

Swagger helps you to manage your API's from the code base itself. You don't need to go for any other third party API testing tools like Postman,Soap UI etc.

So here are the integration steps.



Step 1:
Create a .Net core web api project using visual studio

Step 2:
Install the 'Swashbuckle.AspNetCore' nuget package using Nuget package manager

Step 3:
Go to the Startup.cs file in the project and below code in the 'Configure' method.

        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json","Inventory API");
        });
Step 4: Add the below code in 'ConfigureServices' method
       services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info
            {
                Version = "v1",
                Title = "Inventory API",
                Description = "Testing"  
            });
        });

You need only these 4 steps to integrate the swagger UI.

Now run the project in visual studio and in browser add swagger after the  localhost port and hit enter
Bingo your swagger is ready to use.
https://localhost:44309/swagger/index.html

Another way is change the launch url in launchSetting.json to swagger
which is present under the project proerties

"profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }



Vue Cli 3 typescript application integrated with moviedb

If your looking for a template project for Vue Cli integrated with moviedb you can find it in below git hub repository.


https://github.com/tonytomk/moviemaniac

You can get the api key from movie db by registering there.

In the above github code you need to replace the key in the moviecomponent.

Technologies used : vuejs,typescript,vuecli,bootstrap

How to find the factorial of a number using c#

There are two approaches you can try for the above scenario one is with recursion and another one is using for loop.



        

  static void Main(string[] args)
        {
           int rslt= FactorialWithoutR(5);
           Console.WriteLine("Factorial is :{0}", rslt);
        }

        public static int Factorial(int limit)
        {
            // Using Recursion
            if (limit == 0)
            {
                return 1;
            }
            return limit * Factorial(limit - 1);
        }

        public static int FactorialWithoutR(int limit)
        {

            int factorial = 1;
            for (int i = 1; i <= limit; i++)
            {
                factorial = factorial * i;
            }
            return factorial;
        }

How to create Fibonacci series for the given limit using C#

Please find the solution for the same below.




















        

  static void Main(string[] args)
        {
            Fibonacci(10);
        }

        public static void Fibonacci(int limit)
        {
            // Method 1
            int a = 0; int b = 1; int c=0;
            Console.WriteLine("Method 1");
            Console.WriteLine("Fib Series : {0},{1}", a, b);
            for(int i = 2; i < limit; i++)
            {
                c = a + b;
                Console.Write("{0} ",c);
                a = b;
                b = c;

            }

            // Method 2
            int[] fibnArray = new int[limit];
            fibnArray[0] = 0;
            fibnArray[1] = 1;

            for (int i = 2; i < limit; i++)
            {
                fibnArray[i] = fibnArray[i - 2] + fibnArray[i - 1];
            }

            string fib1 = "";
            fibnArray.ToList().ForEach(x => { fib1 = fib1 + x.ToString() + ","; });
            Console.WriteLine("\n Method 2");
            Console.WriteLine("Fibonacci Series " + fib1);

            //Method 3
            Console.WriteLine("Method 3");
            Recurring(0, 1, 1, 10);
            // Method 4
            List fibnList = new List();
            for (int i = 0; i < limit; i++)
            {
                if (i == 0 || i == 1)
                {
                    fibnList.Add(i);
                }
                else
                {
                    fibnList.Add(fibnList[i - 2] + fibnList[i-1]);
                }

            }
            string fib = "";
            fibnList.ForEach(x => { fib = fib + x.ToString() + ","; });
            Console.WriteLine("\n Method 4");
            Console.WriteLine("Fibonacci Series " + fib);
            Console.ReadLine();
        }

        public static void Recurring(int a,int b,int counter,int limit)
        {
            if (counter < limit)
            {
                Console.Write(a);
                int c = a + b;
                counter = counter + 1;
                Recurring(b, c,counter , limit);
            }
                    
        }