Software Architect at Genzeon Corporation in Malvern, Pennsylvania, Microsoft .NET MVP, Husband, Dad and Geek.
25187 stories
·
21 followers

Localization for Xamarin.Forms with RTL detection

1 Share

Localization for Xamarin.Forms, Xamarin.iOS, Xamarin.Android, Xamarin.Mac and Xamarin.WPF

It's a pleasure to announce this brand new, powerfull net standard plugin for handling language localization in Xamarin.Forms (3.0).

NuGet

Features

  • Get and set current culture
  • Get device culture
  • Ensure device culture match available cultures or set a default culture even when culture are neutral and device culture is not.
  • Get culture list
  • Get specific culture by name
  • Raise event when current culture change to update Resources Culture
  • Detect FlowDirection based on current culture :gift:
  • No markup extension needed to bind resource messages
  • Intellisense available for Resources :heart:

Platform Support

|Platform|Version| | ------------------- | :------------------: | |Mono| 5.4+| |Xamarin.Forms| 3.0+| |Xamarin.iOS|iOS 10.14+| |Xamarin.Android|API 14+| |Windows 10 UWP|10+| |Xamarin.Mac|+3.8| |watchOS|All| |tvOS|All|

Setup

  • Install into your Net Standard project (clients are not needed).

  • If you want to use in Android, iOS with no Xamarin.Forms dependency use the Sources package.

Getting Started

  1. Add your Resx files

  1. Add one .resx file per language you want to support. As you can imagine it must follow a specific naming convention: use the same filename as the base resources file (eg. Messages) followed by a period (.) and then the language code.

  1. In order to recognize the device language, you can use EnsureDeviceOrDefaultCulture, if device's language match available cultures, that culture will be set, otherwise, defaultCultureName will be used.
       Localization.Current.EnsureDeviceOrDefaultCulture(defaultCultureName:"en",
                                    availableCultures:new []{"en","ar","fr"});
  1. Set the culture of your resource class file when initializing your application.
       Messages.Culture = Localization.Current.CurrentCultureInfo;
  1. Ensure that you handle the language change event to ensure resource class Culture matchs.
       Localization.Current.OnCultureChanged += (culture)=>
       {
           Messages.Culture = culture;
       };

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

Xamarin Forms Specifics

This pacakage depends on new Xamarin.Forms 3.0 package with support to RTL content.

To use the resources in XAML, you need to import your resource class namespace and set any property value using the Static expression. You don't need any custom markup extension and it brings Intellisense support ;)

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 Details

Call Localization.Current from any project or .net standard library project to gain access to APIs.

CurrentCultureInfo

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

Usage sample:

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

CurrentNeutralCultureInfo

Gets the neutral culture version of the current culture.

Usage sample:

    Localization.Current.CurrentNeutralCultureInfo;

DeviceCultureInfo

Gets the device culture

Usage sample:

    Localization.Current.DeviceCultureInfo;

CultureInfoList

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

Usage sample:

    Localization.Current.CultureInfoList;

NeutralCultureInfoList

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

Usage sample:

    Localization.Current.NeutralCultureInfoList;

GetCultureInfo

Gets a specific culture by language code.

Usage sample:

    Localization.Current.GetCultureInfo("es");

IsRightToLeft

Gets true if the current culture is RTL language.

Usage sample:

    Localization.Current.IsRightToLeft

FlowDirection

Gets a FlowDirection enum value used for Xamarin.Forms to add RTL support. For more information, review https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/localization/right-to-left.

Usage sample:

      public partial class MainPage : ContentPage
      {
          public MainPage()
          {
              InitializeComponent();
              FlowDirection = Localization.Current.FlowDirection;
          }
      }

EnsureDeviceOrDefaultCulture(string defaultCultureName, params string[] availableCultures) Try to set the CurrentCultureInfo value based on device culture only if it matches available cultures.

Usage sample:

       Localization.Current.EnsureDeviceOrDefaultCulture(defaultCultureName:"en",
                                    availableCultures:new []{"en","ar","fr"});

OnCultureChanged An event that arises when you change the CurrentCultureInfo.

Usage sample:

       Localization.Current.OnCultureChanged += (culture)=>
       {
           Messages.Culture = culture;
       };

Contributors

Read the whole story
alvinashcraft
2 hours ago
reply
West Grove, PA
Share this story
Delete

SQL SERVER – Maintenance Plan Error: Failed to Acquire Connection “Local Server Connection”.

1 Share

One of my clients had an interesting situation where none of the SQL Maintenance plans were working. The example what I am using here is a SQL Server backup maintenance plan failing. I also saw a behavior where all the individual jobs were working fine as expected.

THE PROBLEM

Here is the error we were seeing in the job history

Description: Failed to acquire connection “Local server connection”. Connection may not be configured correctly or you may not have the right permissions on this connection.  End Error  Warning: 2018-01-21 15:48:36.32     Code: 0x80019002     Source: OnPreExecute     

(A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

From above it is clear that the maintenance plan was not able to connect to this instance of SQL Server. As we know, the Maintenance Plans uses SSIS engine to execute the plans. Every plan which gets created has a connection defined, which gets used during the plan execution. If the connection defined is not correct, the plan execution will fail with the above errors. I suspected something like this to be happening here.

So, I asked my client “the most famous question” in the troubleshooting world – What was changed recently?

and, they replied – “We changed the SQL Server port from default port 1433 to a non-default port 2433”

And I think that was a major clue.

WORKAROUND/SOLUTION

Based on the public documentation, all the jobs created via Maintenance Plans are executed via DTExec.exe which is an external 64-bit client process. This process tried to connect to the instance of SQL Server before executing the assigned step. Here is the place to see the connections.

SQL SERVER - Maintenance Plan Error: Failed to Acquire Connection "Local Server Connection". mp-fail-01-800x376

As the SQL Port number was changed to a non-default port, either we need to put that in connection (as shown above) or create SQL Server client-side alias for this instance, locally, using the new port number.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – Maintenance Plan Error: Failed to Acquire Connection “Local Server Connection”.

Read the whole story
alvinashcraft
2 hours ago
reply
West Grove, PA
Share this story
Delete

Learn Kotlin Fast with new Kotlin Bootcamp course

1 Share

Posted by Aleks Haecky, Training Developer & Word Artist, Google+, LinkedIn, Medium

The Kotlin Bootcamp Udacity course is a free, self-paced online course that teaches you the basics of the Kotlin programming language. This introduction to Kotlin was created by Google experts in collaboration with Udacity and is for people who already know how to program.

The Kotlin language lets you create apps in less time, writing less code, and with fewer errors.

This modern object-oriented language offers a strong type system, type inference, null safety, properties, lambdas, extensions, coroutines, higher-order functions, and many other features. Kotlin is so concise that you can create complete data classes with a single line of code.

Kotlin is officially supported for building Android apps, fully interoperates with the Java programming language and libraries, and is included with IntelliJ and Android Studio.

In this course you will learn everything you need to program in Kotlin, including:

  1. Basics: Write Kotlin statements and expressions in the IntelliJ REPL Kotlin interpreter using nullable and non-nullable variables, data types, operators, and control structures.
  2. Functions: Create a main() function, create and call functions with default and variable arguments, pass functions as arguments to filters, program simple lambdas, function types, and compact single-expression functions.
  3. Classes: Create a class with methods and properties. Implement constructors and init(). Learn about inheritance, interfaces, and abstract classes. Use the special purpose classes data, object, enum, and sealed.
  4. Beyond the Basics: Dive deeper into Pairs, collections, and constants. Learn how to write extensions, implement generics, apply annotations, and use labeled breaks.
  5. Functional Manipulation: Explore more about lambdas, higher-order functions, and inline.

You'll learn how to use extension functions to add helpful functionality to existing classes.

Extend built-in types:

fun Int.print() = println(this)
5.print() // prints 5

Extend Android classes:

fun Context.toast(text: CharSequence, duration: Int = Toast.LENGTH_SHORT): Toast {
   return Toast.makeText(this, text, duration).apply { show() }
}
toast("Hello Toast")

Extend your own classes:

class AquariumPlant(
       val color: String)

fun AquariumPlant.print() =
       println("Pretty Aquarium Plant")

val plant = AquariumPlant("green")
plant.print()
// prints -> Pretty Aquarium Plant

When you've completed the course, you will be able to create programs in Kotlin, taking advantage of the features and capabilities that make Kotlin unique.

The course is available free, online at Udacity; take it in your own time at your own pace.

Go learn how to build apps with less code at https://www.udacity.com/course/ud9011.

Read the whole story
alvinashcraft
2 hours ago
reply
West Grove, PA
Share this story
Delete

TypeScript – A Tour of Generics

1 Share
TypeScript is the evolution of JavaScript and its language services are far superior to any other JavaScript tool in existence today. Generics are a fantastic way to demonstrate this powerful advancement for JavaScript development. In this tutorial, we'll focus on generics in TypeScript.
Read the whole story
alvinashcraft
3 hours ago
reply
West Grove, PA
Share this story
Delete

243: Thomas Dang

1 Share

If there's anything I learned from talking with Thomas Dang, it's that he really puts a lot of effort into not just making sure his work is seen, but that it's felt as well. That can be a difficult thing for a graphic designer to do, but Thomas' unique mix of skills gives him a perspective many others don't have.

Thomas is currently pursuing his MBA while freelancing, so we talked about how what he's studying factors into his life as a designer. From there, Thomas shared the early days of his career, gave his thoughts on the Cleveland design community, and he talked about his dream project of reaching out and teaching design to his local community. I appreciate Thomas for being so candid and open about his life, and thanks to Alex Binder for the introduction!


Help support Revision Path by becoming a monthly patron on Patreon! For just $5 per month, you’ll receive behind-the-scenes access to Revision Path, including special patron-only updates, early access to future episodes, and a lot more! Join today!


We're on Apple Podcasts, Spotify and Stitcher! Visit https://revisionpath.com/iTunes, https://revisionpath.com/spotify or https://revisionpath.com/stitcher, subscribe, and leave us a 5-star rating and a review! Thanks so much to all of you who have already rated and reviewed us!


Revision Path is brought to you by Facebook Design, Glitch, Google Design, and MailChimp.


Follow Revision Path on Facebook, Twitter, and Instagram!





Download audio: https://dts.podtrac.com/redirect.mp3/audio.simplecast.com/d1339f8f.mp3
Read the whole story
alvinashcraft
3 hours ago
reply
West Grove, PA
Share this story
Delete

Non Nullable Reference Types in Upcoming C# 8

1 Share

NON-NULLABLE Reference Types

In today's blog post, I will be discussing one of the new & exciting feature of upcoming C#8. The work is currently under way. This is more of a sneak preview :)

Currently, whenever we have a reference type, it's always nullable by default. If I don't assign any value to a reference type, it defaults to null. Furthermore, as a programmer, there is no way to specify that for this specific reference, I want to disallow nulls. As a result, these nulls do sneak into our applications and cause the famous Null reference exceptions. Tony Hoare, the guy who invented Null, called it his billion dollar mistake. I am pretty sure, it has costed more than that by now!

This feature attempt is to reduce these null reference exceptions. The biggest hurdle is, if C# 8 disallows nulls on reference types completely, then it's not backward compatible. So this feature is going to be an opt-in feature. The idea is that slowly people will adopt this feature and as more and more code becomes compatible to this feature, they can completely turn off the switch for default nulls sometime in future.

Non Nullable reference Type C# 8
The feature will provide the ability to the programmer to make the decision consciously whether to allow nulls or not to reference types, similar to the way we do it for primitive types. For e.g. when I say


int? x; // explicitly nullable

If I don't put "?" then nulls are disallowed.

So using similar syntax, the plan is, if you opt in the feature for not allowing reference types to be null, then any code like this will throw a warning:


string str = null; //Warning

Now, to fix this, you have 2 options:
Either, you will have to explicitly make it nullable like this:


string? str = null;

OR

Assign it something other than null and expect that null will never be assigned to this reference.

string str = "text";

This way you are consciously making decision of allowing or disallowing nulls for these reference types too.

With that said, with the last syntax above, there are ways to still assign nulls to this reference indirectly at run time and still get Null reference exception. Not everything can be known at compile time. But the idea is that the exception will become less common.

CONCLUSION

I think this a great step by C# team to improve the code quality and reduce the number of run time exceptions. With each and every version, the C# language is moving towards better. Happy coding :)

Read the whole story
alvinashcraft
3 hours ago
reply
West Grove, PA
Share this story
Delete
Next Page of Stories