ctkPluginLocalization.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * \ingroup PluginFramework
  25. *
  26. * Translate text into different languages.
  27. *
  28. * Use this class to dynamically translate human-readable text
  29. * in your plugin. You can get an instance of this class
  30. * corresponding to a specific locale via the method
  31. * <code>ctkPlugin::getPluginLocalization()</code>.
  32. *
  33. * @see ctkPlugin::getPluginLocalization()
  34. */
  35. class CTK_PLUGINFW_EXPORT ctkPluginLocalization
  36. {
  37. public:
  38. /**
  39. * Creates a default ctkPluginLocalization instance, using
  40. * the default locale.
  41. *
  42. * Note that getLocalized() will always return a null QString
  43. * for a default constructed ctkPluginLocalization object.
  44. * Use <code>ctkPlugin::getPluginLocalization()</code> to create
  45. * a valid instance.
  46. */
  47. ctkPluginLocalization();
  48. ctkPluginLocalization(const ctkPluginLocalization& pl);
  49. ~ctkPluginLocalization();
  50. ctkPluginLocalization& operator=(const ctkPluginLocalization& other);
  51. /**
  52. * Translate <code>str</code> to a specific locale, using the
  53. * specified <code>context</code>.
  54. *
  55. * @return The translation or a null QString, if no translation
  56. * was found.
  57. */
  58. QString getLocalized(const QString& context, const QString& str) const;
  59. /**
  60. * Get the locale for which this <code>ctkPluginLocalization</code>
  61. * object was constructed.
  62. *
  63. * @return The locale for this object.
  64. */
  65. QLocale getLocale() const;
  66. private:
  67. friend class ctkPlugin;
  68. ctkPluginLocalization(const QString& msgFileName,
  69. const QLocale& locale, const QSharedPointer<ctkPlugin>& plugin);
  70. mutable QSharedDataPointer<ctkPluginLocalizationData> d;
  71. };
  72. #endif // CTKPLUGINLOCALIZATION_H