Exemplo n.º 1
0
        /// <summary>
        /// Gets the localized string according to language selcted.
        /// </summary>
        /// <param name="key">Key.</param>
        /// <param name="comments">Comments.</param>
        public string GetLocalizedString(string key, string comments)
        {
            // Get the language code.
            NSString languageCode = new NSString(Settings.CurrentLanguage);

            // Get the relevant language bundle.
            var      bundlePath = NSBundle.MainBundle.PathForResource(languageCode, "lproj");
            NSBundle languageBundle;

            if (bundlePath != null)
            {
                languageBundle = NSBundle.FromPath(bundlePath);
            }
            else
            {
                languageBundle = NSBundle.MainBundle;
            }
            // Get the translated string using the language bundle.
            var translatedString = languageBundle.LocalizedString(key, comments);

            if (translatedString.Length < 1)
            {
                // There is no localizable strings file for the selected language.
                translatedString = NSBundle.MainBundle.LocalizedString(key, comments);
            }

            return(translatedString);
        }
        public static Version GetVersionOfAppBundle(string appBundlePath)
        {
            if (!Directory.Exists(appBundlePath))
            {
                return(null);
            }

            using (var bundle = NSBundle.FromPath(appBundlePath))
            {
                var info = bundle?.InfoDictionary;
                if (info == null)
                {
                    return(null);
                }
                var versionString = info.ObjectForKey(s_VersionKey) as NSString;
                if (versionString != null && Version.TryParse(versionString, out var version))
                {
                    return(version);
                }
                var shortVersionString = info.ObjectForKey(s_ShortVersionKey) as NSString;
                if (shortVersionString != null && Version.TryParse(shortVersionString, out version))
                {
                    return(version);
                }
                return(null);
            }
        }
Exemplo n.º 3
0
 public ViewsFactory(IApplication app)
 {
     this.app    = app;
     this.bundle = new Lazy <NSBundle>(
         () => NSBundle.FromPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)),
         LazyThreadSafetyMode.None
         );
 }
Exemplo n.º 4
0
        public static string GetString(string localizedString)
        {
            var    db             = DatabaseHelpers.GetDatabase();
            string languageCode   = "el";
            var    path           = NSBundle.MainBundle.PathForResource(languageCode, "lproj");
            var    languageBundle = NSBundle.FromPath(path);

            return(languageBundle.LocalizedString(localizedString, "", ""));
        }
        public string GetLocalizedString(string culture, string key)
        {
            //you must have culture resource folder

            var path           = NSBundle.MainBundle.PathForResource(culture, "lproj");
            var languageBundle = NSBundle.FromPath(path);

            return(languageBundle.LocalizedString(key, string.Empty));
        }
Exemplo n.º 6
0
        static Settings()
        {
            string resourcePath = NSBundle.MainBundle.PathForResource(NSLocale.PreferredLanguages[0], "lproj");

            if (string.IsNullOrEmpty(resourcePath))
            {
                resourcePath = NSBundle.MainBundle.PathForResource("en", "lproj");
            }

            localeBundle = NSBundle.FromPath(resourcePath);
        }
Exemplo n.º 7
0
        public override void ShowHUDInView(UIKit.UIView view, string message, Interactor interactor)
        {
            if (Instance == null)
            {
                Instance = MBProgressHUD.ShowHUDAddedTo(view, true);
            }

            ConfigureAndShowHUD(Instance,
                                NSBundle.FromPath(NSBundle.MainBundle.PathForResource(LanguageHelper.Language, "lproj")).LocalizedString("Loading...", null),
                                ProgressCloseMode.ManualClose,
                                ProgressSpinnerMode.IndeterminateSpinner);
        }
Exemplo n.º 8
0
        UIImage bubbleImageFromBundleWithName(string name)
        {
            var bundle = NSBundle.FromClass(new ObjCRuntime.Class(typeof(MessagesViewController)));

            string bundleResourcePath  = bundle.ResourcePath;
            string assetPath           = System.IO.Path.Combine(bundleResourcePath, "JSQMessagesAssets.bundle");
            var    messagesAssetBundle = NSBundle.FromPath(assetPath);


            var path = messagesAssetBundle.PathForResource(name, "png", "Images");

            return(UIImage.FromFile(path));
        }
Exemplo n.º 9
0
        public static bool SetProgramLanguageCode(string langCode)
        {
            var path = NSBundle.MainBundle.PathForResource(langCode, "lproj");

            if (string.IsNullOrEmpty(path))
            {
                // Translations not found.. no change
                Console.WriteLine("Translations not found for {0}", langCode);
                return(false);
            }
            m_bundle    = NSBundle.FromPath(path);
            CurrentCode = langCode;
            return(true);
        }
 public static void SetLanguage(string lan)
 {
     Culture = new CultureInfo(DefaultCulture);
     if (lan.Equals("en"))
     {
         LanguageBundle = NSBundle.FromPath(NSBundle.MainBundle.PathForResource(lan, "lproj"));
         ActiveLanguage = lan;
     }
     else if (lan.Equals("el"))
     {
         LanguageBundle = NSBundle.FromPath(NSBundle.MainBundle.PathForResource(lan, "lproj"));
         ActiveLanguage = lan;
     }
     else
     {
         LanguageBundle = NSBundle.FromPath(NSBundle.MainBundle.PathForResource(DefaultLanguage, "lproj"));
         ActiveLanguage = DefaultLanguage;
     }
 }
Exemplo n.º 11
0
        public void SetLanguage(string lang, bool manual = false)
        {
            var settingsService = Locator.Current.GetService <ISettingsService>();

            settingsService.AddOrUpdateValue(STORE_LANG, lang);
            settingsService.AddOrUpdateValue(MANUAL_LANG, manual);

            NSUserDefaults.StandardUserDefaults.SetValueForKey(NSArray.FromStrings(lang), new NSString("AppleLanguages"));
            NSUserDefaults.StandardUserDefaults.Synchronize();
            if (lang.Equals("en"))
            {
                var path = NSBundle.MainBundle.PathForResource("Base", "lproj");
                AppDelegate.LanguageBundle = NSBundle.FromPath(path);
            }
            else
            {
                var path = NSBundle.MainBundle.PathForResource(lang, "lproj");
                AppDelegate.LanguageBundle = NSBundle.FromPath(path);
            }
        }
Exemplo n.º 12
0
        static int LaunchAppAndWaitForExit(string path, string[] args, bool activate = true)
        {
            var pid    = LaunchApplicationForPath(path, args, activate);
            var retval = WaitForExit(pid);             // returning exit code not implemented in Mono.

            // This hack works only with apps that write their exit code into their defaults under "ExitCode" key and PID under "PID" key.
            var bundleIdentifier = NSBundle.FromPath(path)?.BundleIdentifier;

            if (bundleIdentifier != null)
            {
                var defaults = new NSUserDefaults(bundleIdentifier, NSUserDefaultsType.SuiteName);
                if ((defaults.ValueForKey((NSString)"PID") is NSNumber num) && num.Int32Value == pid)
                {
                    if (defaults.ValueForKey((NSString)"ExitCode") is NSNumber exitCode)
                    {
                        retval = exitCode.Int32Value;
                    }
                }
            }
            return(retval);
        }
Exemplo n.º 13
0
        /* UIViewController */

        public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
        {
            if (segue.Identifier == "forfet")
            {
                var LanguageBundle = NSBundle.FromPath(NSBundle.MainBundle.PathForResource(LanguageHelper.Language, "lproj"));
                var BackItem       = new UIBarButtonItem();
                BackItem.Title     = LanguageBundle.LocalizedString("Back", null);
                BackItem.TintColor = UIColor.White;
                NavigationItem.BackBarButtonItem = BackItem;

                var ViewController = segue.DestinationViewController as ForfetViewController;

                if (ViewController != null)
                {
                    switch (sender.ToString())
                    {
                    case "0":
                        ViewController.ForfetUrl = LanguageHelper.Pages.Mobile;
                        break;

                    case "1":
                        ViewController.ForfetUrl = LanguageHelper.Pages.Roaming;
                        break;

                    case "2":
                        ViewController.ForfetUrl = LanguageHelper.Pages.Paquete69;
                        break;

                    case "3":
                        ViewController.ForfetUrl = LanguageHelper.Pages.Optima;
                        break;

                    default:
                        Console.WriteLine("Invalid page");
                        break;
                    }
                }
            }
        }
        private static NSBundle getFrameworkBundle()
        {
            NSBundle bundle;

            //Check if the bundle was already loaded
            if ((bundle = Volatile.Read(ref frameworkBundle)) != null)
            {
                var path = NSBundle.MainBundle.ResourcePath;
                var frameworkBundlePath = path + "JudoPay.bundle";

                //Try to set the bundle value, if the bundle was already loaded, discard this load and use the existing, else safely read the existing
                if (Interlocked.CompareExchange(ref frameworkBundle, NSBundle.FromPath(frameworkBundlePath), null) == null)
                {
                    bundle = frameworkBundle;
                }
                else
                {
                    bundle = Volatile.Read(ref frameworkBundle);
                }
            }

            return(bundle);
        }
Exemplo n.º 15
0
        private LocalizedStrings()
        {
            var path = NSBundle.MainBundle.PathForResource("en", "lproj");

            __LanguageBundle = NSBundle.FromPath(path);
        }
Exemplo n.º 16
0
 static IOUSB()
 {
     bundle = new Lazy <NSBundle> (() => NSBundle.FromPath(iousbFamilyBundlePath));
 }
Exemplo n.º 17
0
        public static string GetText(string str)
        {
            string path = NSBundle.MainBundle.PathForResource(GlobalCurrentCulture.TwoLetterISOLanguageName.ToLower(), "lproj");

            return(NSBundle.FromPath(path).LocalizedString(str, string.Empty));
        }
        void Locate()
        {
            var bundlePath = NSWorkspace.SharedWorkspace.AbsolutePathForAppBundle(bundleId);

            if (bundlePath == null)
            {
                return;
            }

            Bundle = NSBundle.FromPath(bundlePath);
            if (Bundle == null)
            {
                return;
            }

            AppPath = Bundle.BundlePath;

            if (!Bundle.InfoDictionary.TryGetValue(
                    new NSString("CFBundleName"), out var nameOut) || nameOut == null)
            {
                return;
            }

            Name = nameOut.ToString();

            if (!Bundle.InfoDictionary.TryGetValue(
                    new NSString("CFBundleVersion"), out var versionOut) || versionOut == null)
            {
                return;
            }

            Version = versionOut.ToString();
            System.Version.TryParse(Version, out var sysVersion);

            var updateinfoPath = new FilePath(bundlePath).Combine("Contents", "MacOS", "updateinfo");

            if (updateinfoPath.FileExists)
            {
                var updateinfo = XamarinComponent.ReadUpdateinfoFile(updateinfoPath);
                if (updateinfo != null)
                {
                    Version += $" ({updateinfo})";
                }
            }

            var libraryUrl = NSFileManager.DefaultManager.GetUrl(
                NSSearchPathDirectory.LibraryDirectory,
                NSSearchPathDomain.User,
                null,
                false,
                out var error);

            if (error != null)
            {
                throw new NSErrorException(error);
            }

            if (libraryUrl == null)
            {
                throw new DirectoryNotFoundException("unable to locate user Library directory");
            }

            if (sysVersion == null)
            {
                return;
            }

            var isVsm = bundleId == VSMacBundleId;

            // Do not entertain any of the very first VSM preview releases
            if (isVsm && sysVersion < firstStableVSMVersion)
            {
                return;
            }

            foreach (var compatVersion in new [] {
                $"{sysVersion.Major}.{sysVersion.Minor}",
                $"{sysVersion.Major}.0"
            })
            {
                if (isVsm)
                {
                    PreferencesDirectory = new FilePath(libraryUrl.Path).Combine(
                        "Preferences",
                        "VisualStudio",
                        compatVersion);
                }
                else
                {
                    PreferencesDirectory = new FilePath(libraryUrl.Path).Combine(
                        "Preferences",
                        $"XamarinStudio-{compatVersion}");
                }

                if (PreferencesDirectory.DirectoryExists)
                {
                    break;
                }
            }

            IsInstalled = AppPath.DirectoryExists && !string.IsNullOrEmpty(Version);
        }
Exemplo n.º 19
0
        /* Private methods */

        static NSBundle RetrieveLanguageBundle(string Language)
        {
            var Path = NSBundle.MainBundle.PathForResource(Language, "lproj");

            return(NSBundle.FromPath(Path));
        }
 public static string Translate(this string strName, string locale)
 {
     return(NSBundle.FromPath(NSBundle.MainBundle.PathForResource(locale, "lproj")).LocalizedString(strName, "", ""));
 }