Example #1
0
        public static void AttemptToLocalizeComponent(DependencyObject obj)
        {
            if (obj == null) {
                return;
            }

            KNBundle bundle = KNBundle.BundleWithAssembly(Assembly.GetAssembly(obj.GetType()));

            // Search for a table named directly after the object, or the name of the object
            // plus "Strings". I.e., KNFoundation.KNBundle or KNFoundation.KNBundleStrings.

            string tableName = obj.GetType().ToString();
            Dictionary<string, string> table = bundle.LocalizedStringTableWithName(tableName);

            if (table == null) {
                tableName = obj.GetType().ToString() + "Strings";
                table = bundle.LocalizedStringTableWithName(tableName);
            }

            if (table != null) {

                foreach (string key in table.Keys) {

                    try {
                        obj.SetValueForKeyPath(table.ValueForKey(key), key);
                    } catch { }
                }
            }
        }