Code Monkey home page Code Monkey logo

xamarin-sdk's Introduction

Crowdin Xamarin Forms SDK

The Crowdin Xamarin Forms SDK delivers all new translations from Crowdin project to the application immediately. So there is no need to update the application via Store to get the new version with the localization.

Features

  • Load remote strings from Crowdin Over-The-Air Content Delivery Network
  • Built-in translations caching mechanism (enabled by default, can be disabled)
  • Network usage configuration (All, only Wi-Fi or Cellular, Forbidden)
  • Load static strings from the bundled RESX files (usable as fallback before the CDN strings loaded)

Requirements

  • .NET Standard 2.1 support
  • Xamarin Forms 5.0 or newer

Installation

Install via NuGet:

// Package Manager
Install-Package Crowdin.Xamarin.Forms -Version 0.1.0

// .Net CLI
dotnet add package Crowdin.Xamarin.Forms --version 0.1.0

// Package Reference
<PackageReference Include="Crowdin.Xamarin.Forms" Version="0.1.0" />

// Paket CLI
paket add Crowdin.Xamarin.Forms --version 0.1.0

Quick start

For applications using the XML resource localization files (RESX)

  1. Add Crowdin Distribution Hash before any modules initialization:

    DynamicResourcesLoader.GlobalOptions.DistributionHash = "{your_distribution_hash}";
  2. Load static strings from app resource files to use as fallback:

    DynamicResourcesLoader.LoadStaticStrings(Translations.ResourceManager, Current.Resources);

    The first argument is the source - ResourceManager of the generated class from resources group (Translations.resx and descendants). The second argument is the destination - ResourceDictionary where to place loaded strings:

    • Global: in Application.Current.Resources
    • Per-view: in ContentPage.Resources
  3. Load strings from Crowdin Distributions CDN:

    string langCode = DynamicResourcesLoader.CurrentCulture.TwoLetterISOLanguageName;
    DynamicResourcesLoader.LoadCrowdinStrings($"Translations.{langCode}.resx", Current.Resources);

    The property CurrentCulture provides end-user OS locale by default. It can be overridden by the developer if needed.

    The method LoadCrowdinStrings is async and can be awaited if needed.

    In this example, the method is not “awaited” not to block the rendering of the user’s interface.

Configuration

The SDK provides developers two ways for resources loading configuration: global and per-request:

var options = new CrowdinOptions
{
    DistributionHash = "<your_distribution_hash>",
    NetworkPolicy = NetworkPolicy.OnlyWiFi,
    UseCache = true,
    FileName = "Translations.resx"
};
  • NetworkPolicy - for network restrictions

    • All - all network types allowed
    • OnlyWiFi or OnlyCellular - only needed type allowed
    • Forbidden
  • UseCache - turn on or off built-in translations caching mechanism.

For global configuration override default GlobalOptions:

DynamicResourcesLoader.GlobalOptions = options;

For per-request configuration pass options as the first parameter:

DynamicResourcesLoader.LoadCrowdinStrings(options, Current.Resources);

In a last way don't forget to add options.FileName value. Please note - for this example we used the 'Translations.resx' file name. This name should correspond to the file name in Crowdin.

Translations caching algorithm

Every time the method DynamicResourcesLoader.LoadCrowdinStrings is executed the module checks the conditions for obtaining resources, updating or creating a cache (if it does not exist).

  1. If the cache is disabled and the network is unavailable - exit;
  2. If the cache is disabled, the network is available - resources are downloaded directly from the Crowdin CDN every time;
  3. If the cache is enabled, not yet created, the network is not available - exit;
  4. If the cache is enabled, not yet created, the network is available - resources are downloaded from the CDN and stored in the cache;
  5. If the cache is enabled, created - the cache is used first. The following is executed in the background thread:
    • Check network availability. If not - exit;
    • Update Crowdin manifest with updated translation date;
    • Comparison of creation dates of cached and remote resources. If they are the same - exit;
    • Update resources from Crowdin CDN;

P.S. The network is considered unavailable even if the user has forbidden its use in the loader settings.

Contribution

If you want to contribute please read the Contributing guidelines.

Seeking Assistance

If you find any problems or would like to suggest a feature, please feel free to file an issue on Github at Issues Page.

Need help working with Crowdin Xamarin Forms SDK or have any questions? Contact Customer Success Service.

License

The Crowdin Xamarin Forms SDK is licensed under the MIT License.
See the LICENSE file distributed with this work for additional
information regarding copyright ownership.

Except as contained in the LICENSE file, the name(s) of the above copyright
holders shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written authorization.

xamarin-sdk's People

Contributors

andrii-bodnar avatar innomaxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xamarin-sdk's Issues

is there MAUI support planned?

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

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.