ctkPluginLocalization.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKPLUGINLOCALIZATION_H
  16. #define CTKPLUGINLOCALIZATION_H
  17. #include <ctkPluginFrameworkExport.h>
  18. #include <QLocale>
  19. #include <QSharedDataPointer>
  20. #include <QSharedPointer>
  21. class ctkPlugin;
  22. struct ctkPluginLocalizationData;
  23. /**
  24. * Translate text into different languages.
  25. *
  26. * Use this class to dynamically translate human-readable text
  27. * in your plugin. You can get an instance of this class
  28. * corresponding to a specific locale via the method
  29. * <code>ctkPlugin::getPluginLocalization()</code>.
  30. *
  31. * @see ctkPlugin::getPluginLocalization()
  32. */
  33. class CTK_PLUGINFW_EXPORT ctkPluginLocalization
  34. {
  35. public:
  36. /**
  37. * Creates a default ctkPluginLocalization instance, using
  38. * the default locale.
  39. *
  40. * Note that getLocalized() will always return a null QString
  41. * for a default constructed ctkPluginLocalization object.
  42. * Use <code>ctkPlugin::getPluginLocalization()</code> to create
  43. * a valid instance.
  44. */
  45. ctkPluginLocalization();
  46. ctkPluginLocalization(const ctkPluginLocalization& pl);
  47. ~ctkPluginLocalization();
  48. ctkPluginLocalization& operator=(const ctkPluginLocalization& other);
  49. /**
  50. * Translate <code>str</code> to a specific locale, using the
  51. * specified <code>context</code>.
  52. *
  53. * @return The translation or a null QString, if no translation
  54. * was found.
  55. */
  56. QString getLocalized(const QString& context, const QString& str) const;
  57. /**
  58. * Get the locale for which this <code>ctkPluginLocalization</code>
  59. * object was constructed.
  60. *
  61. * @return The locale for this object.
  62. */
  63. QLocale getLocale() const;
  64. private:
  65. friend class ctkPlugin;
  66. ctkPluginLocalization(const QString& msgFileName,
  67. const QLocale& locale, const QSharedPointer<ctkPlugin>& plugin);
  68. mutable QSharedDataPointer<ctkPluginLocalizationData> d;
  69. };
  70. #endif // CTKPLUGINLOCALIZATION_H