string CurrentLanguage() { var currentCulture = StringResources.Culture ?? Localize.GetCurrentCultureInfo(); int currentLanguage = SupportedLanguages.FindIndex((lang) => lang.Code == currentCulture.TwoLetterISOLanguageName); // The language of the device may be in one not supported, e.g. Norsk. if (currentLanguage == -1) { currentLanguage = SupportedLanguages.FindIndex((lang) => lang.Code == "en"); } return(SupportedLanguages[currentLanguage].Endonym); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { UIApplication.SharedApplication.IdleTimerDisabled = true; // If the user is not logged in (hence has not created an account), then show the login view. // The Root view (i.e. TabBarController) is shown and set once the user login or registers. if (string.IsNullOrEmpty(NSUserDefaults.StandardUserDefaults.StringForKey("tokens"))) { // Required to show onboarding in native device language or English if resources dont exist. StringResources.Culture = Localize.GetCurrentCultureInfo(); Window.RootViewController = UIStoryboard.FromName("Main", null).InstantiateViewController("Onboarding"); } // Used by the PCL for database interactions so must be defined early. Session.PrivatePath = new PrivatePath(); // Register the implementation to the global interface within the PCL. RestClient.GlobalIO = new DiskIO(); if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { UNUserNotificationCenter.Current.Delegate = this; // Request notification permissions from the user UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => { }); } else { var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings); } UIApplication.SharedApplication.RegisterForRemoteNotifications(); Messaging.SharedInstance.Delegate = this; Messaging.SharedInstance.ShouldEstablishDirectChannel = true; // Create here as this method will always get run when opening the app. Firebase.Crashlytics.Crashlytics.Configure(); Firebase.Core.App.Configure(); return(true); }
private void Localization() { var localize = new Localize(); AppResources.Culture = localize.GetCurrentCultureInfo(); }
public async override void ViewDidLoad() { base.ViewDidLoad(); var SupportedLanguages = (await LanguageChoiceManager.GetLanguageChoices()).OrderBy((lang) => lang.Code).ToList(); TableView.RegisterNibForCellReuse(ProjectTableViewHeader.Nib, ProjectTableViewHeader.CellID); TableView.RowHeight = UITableView.AutomaticDimension; TableView.EstimatedRowHeight = 250; if (Session.ActiveUser == null) { var email = NSUserDefaults.StandardUserDefaults.StringForKey("username"); var user = Queries.UserByEmail(email); var _tokens = NSUserDefaults.StandardUserDefaults.StringForKey("tokens"); var tokens = JsonConvert.DeserializeObject <JWToken>(_tokens); Queries.SetActiveUser(new DataUserTokens { User = user, Tokens = tokens }); Firebase.Analytics.Analytics.SetUserId(Session.ActiveUser.Id.ToString()); // If the user has set the preference or is was determined below, we want to apply it Session.ActiveUser.AppLang = user.AppLang; } var currentMobileLang = Localize.GetCurrentCultureInfo().TwoLetterISOLanguageName; var isSupportedLang = SupportedLanguages.FindIndex((lang) => lang.Code == currentMobileLang); // If the user has logged in for the first time, then // and their mobile language is one we support, then we must choose that. if (isSupportedLang != -1 && Session.ActiveUser.AppLang == 0) { Session.ActiveUser.AppLang = SupportedLanguages.First((lang) => lang.Code == currentMobileLang).Id; } // Otherwise, the user who logged in, may not have their phone in a lang we do not support else if (isSupportedLang == -1 && Session.ActiveUser.AppLang == 0) { Session.ActiveUser.AppLang = 1; } Queries.SaveActiveUser(); var languages = SupportedLanguages.FirstOrDefault((lang) => lang.Id == Session.ActiveUser.AppLang); StringResources.Culture = new CultureInfo(languages.Code); Localize.SetLayoutDirectionByPreference(); SetStringResources(); projects = Queries.AllProjects(); refreshControl = new UIRefreshControl { AttributedTitle = new NSAttributedString(StringResources.projects_ui_fetching), TintColor = UIColor.FromCGColor(Application.MainColour) }; refreshControl.AddTarget(delegate { Logger.LOG_EVENT_WITH_ACTION("SWIPE_REFRESH", projects.Count.ToString(), "PROJECT_COUNT"); var suppress = RefreshData(); }, UIControlEvent.AllEvents); ProjectsTableViewSource source = new ProjectsTableViewSource(projects, LaunchProject, HandleExpansion); TableView.Source = source; TableView.RefreshControl = refreshControl; TableView.ReloadData(); var suppressAsync = RefreshData(); SendFCMToken(); }