Code Monkey home page Code Monkey logo

multilingualplugin's Introduction

Multilingual Plugin for Xamarin Forms, Xamarin iOS , Xamarin Android, Xamarin Mac, tvOS, watchOS and Windows

Simple cross platform plugin for handling language localization.

Features

  • Get and set current culture
  • Get device culture
  • Get culture list
  • Get specific culture by name

Platform Support

Platform Version
Xamarin.iOS iOS 7+
Xamarin.Android API 10+
Windows 10 UWP 10+
Xamarin.Mac All
watchOS All
tvOS All

Setup

Getting Started

  1. Add your Resx files

Add one resx file per each language you want to support. "It must follow a specific naming convention: use the same filename as the base resources file (eg. AppResources) followed by a period (.) and then the language code".

  1. Set the culture of your resource class file when initializing your application.

For example:

  AppResources.Culture = CrossMultilingual.Current.DeviceCultureInfo;

If you are using Xamarin Forms it would be in your App.cs

Xamarin Forms Specifics

When installing the plugin it will create a TranslateExtension.txt file in folder Helpers, rename the extension for this file to TranslateExtension.cs.

In TranslateExtension.cs file in the constant ResourceId by default it will assume your resource file is added in the root of the project and the resx file is named as AppResources. If you added it to a folder or named the resx file differently you can change it there.

XAML sample usage:

iOS Considerations

In the Info.plist file add the keys Localizations & Localization native development region to change the user interface OS elements. It will take the device language.

API Usage

Call CrossMultilingual.Current from any project or PCL to gain access to APIs.

CurrentCultureInfo

Gets and set the current culture. By default will be set to the device culture.

Usage sample:

  CrossMultilingual.Current.CurrentCultureInfo = new CultureInfo("en");

Note: After changing the current culture is important to update your resx class culture. As follows:

AppResources.Culture = CrossMultilingual.Current.CurrentCultureInfo;

DeviceCultureInfo

Gets the device culture

Usage sample:

  CrossMultilingual.Current.DeviceCultureInfo;

CultureInfoList

Gets all cultures supported in .NET Framework (neutral & specific cultures)

Usage sample:

  CrossMultilingual.Current.CultureInfoList;

NeutralCultureInfoList

Gets all cultures associated with a language (not specific to a country/region).

Usage sample:

  CrossMultilingual.Current.NeutralCultureInfoList;

GetCultureInfo

Gets a specific culture by language code.

Usage sample:

  CrossMultilingual.Current.GetCultureInfo("es");

In case you want to know more about localization:

https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/

Contributors

multilingualplugin's People

Contributors

char0394 avatar rdelrosario avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.