/core/externals/update-engine/externals/google-toolbox-for-mac/iPhone/GTMUILocalizer.h

http://macfuse.googlecode.com/ · C++ Header · 81 lines · 16 code · 6 blank · 59 comment · 0 complexity · dfe313b8b8c28c4f1f0bf37bb035c864 MD5 · raw file

  1. //
  2. // GTMUILocalizer.h
  3. //
  4. // Copyright 2011 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <UIKit/UIKit.h>
  19. // A class for localizing nibs by doing simple string replacement.
  20. // To use this, make an instance of GTMUILocalizer in your nib. Connect the
  21. // owner outlet of the your instance to the File Owner of the nib. It expects
  22. // the owner outlet to be an instance or subclass of UIViewController. Using
  23. // the bundle of the nib it will then localize any items in the
  24. // UIViewController's view and subviews when awakeFromNib is called on the
  25. // GTMUILocalizer instance.
  26. // You can optionally hook up otherObjectToLocalize and
  27. // yetAnotherObjectToLocalize and those will also be localized. Strings in the
  28. // nib that you want localized must start with ^ (shift-6). The strings will
  29. // be looked up in the Localizable.strings table without the caret as the
  30. // key.
  31. //
  32. // As an example if I wanted to localize a button with the word "Print" on
  33. // it, I would put it in a view controlled by a UIViewController that was
  34. // the owner of the nib. I would set it's title to be "^Print". I would then
  35. // create an instance of GTMUILocalizer and set it's owner to be the owner
  36. // of the nib.
  37. // In my Localizable.strings file in my fr.lproj directory for the bundle
  38. // I would put "Print" = "Imprimer";
  39. // Then when my app launched in French I would get a button labeled
  40. // "Imprimer". Note that GTMUILocalizer is only for strings, and doesn't
  41. // resize, move or change text alignment on any of the things it modifies.
  42. // If you absolutely need a caret at the beginning of the string
  43. // post-localization, you can put "Foo" = "^Foo"; in your strings file and
  44. // it will work.
  45. // Your nib could be located in a variety of places depending on what you want
  46. // to do. I would recommend having your "master" nib directly in Resources.
  47. // If for some reason you needed to do some custom localization of the
  48. // nib you could copy the master nib into your specific locale folder, and
  49. // then you only need to adjust the items in the nib that you need to
  50. // customize. You can leave the strings in the "^Foo" convention and they
  51. // will localize properly. This keeps the differences between the nibs down
  52. // to the bare essentials.
  53. //
  54. @interface GTMUILocalizer : NSObject {
  55. @private
  56. id owner_;
  57. id otherObjectToLocalize_;
  58. id yetAnotherObjectToLocalize_;
  59. NSBundle *bundle_;
  60. }
  61. @property(nonatomic, assign) IBOutlet id owner;
  62. @property(nonatomic, assign) IBOutlet id otherObjectToLocalize;
  63. @property(nonatomic, assign) IBOutlet id yetAnotherObjectToLocalize;
  64. - (id)initWithBundle:(NSBundle *)bundle;
  65. // Localize |object|. If |recursive| is true, it will attempt
  66. // to localize objects owned/referenced by |object|.
  67. - (void)localizeObject:(id)object recursively:(BOOL)recursive;
  68. // A method for subclasses to override in case you have a different
  69. // way to go about getting localized strings.
  70. // If |string| does not start with ^ you should return nil.
  71. // If |string| is nil, you should return nil
  72. - (NSString *)localizedStringForString:(NSString *)string;
  73. // Allows subclasses to override how the bundle is picked up
  74. + (NSBundle *)bundleForOwner:(id)owner;
  75. @end