ResourceLoaderLanguageDataModule.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @author Santhosh Thottingal
  20. */
  21. /**
  22. * Module for populating language specific data, such as grammar forms.
  23. *
  24. * @ingroup ResourceLoader
  25. * @internal
  26. */
  27. class ResourceLoaderLanguageDataModule extends ResourceLoaderFileModule {
  28. protected $targets = [ 'desktop', 'mobile' ];
  29. /**
  30. * Get all the dynamic data for the content language to an array.
  31. *
  32. * @param ResourceLoaderContext $context
  33. * @return array
  34. */
  35. protected function getData( ResourceLoaderContext $context ) {
  36. $language = Language::factory( $context->getLanguage() );
  37. return [
  38. 'digitTransformTable' => $language->digitTransformTable(),
  39. 'separatorTransformTable' => $language->separatorTransformTable(),
  40. 'minimumGroupingDigits' => $language->minimumGroupingDigits(),
  41. 'grammarForms' => $language->getGrammarForms(),
  42. 'grammarTransformations' => $language->getGrammarTransformations(),
  43. 'pluralRules' => $language->getPluralRules(),
  44. 'digitGroupingPattern' => $language->digitGroupingPattern(),
  45. 'fallbackLanguages' => $language->getFallbackLanguages(),
  46. 'bcp47Map' => LanguageCode::getNonstandardLanguageCodeMapping(),
  47. ];
  48. }
  49. /**
  50. * @param ResourceLoaderContext $context
  51. * @return string JavaScript code
  52. */
  53. public function getScript( ResourceLoaderContext $context ) {
  54. return parent::getScript( $context )
  55. . 'mw.language.setData('
  56. . $context->encodeJson( $context->getLanguage() ) . ','
  57. . $context->encodeJson( $this->getData( $context ) )
  58. . ');';
  59. }
  60. /**
  61. * @return bool
  62. */
  63. public function enableModuleContentVersion() {
  64. return true;
  65. }
  66. /**
  67. * @return bool
  68. */
  69. public function supportsURLLoading() {
  70. return false;
  71. }
  72. }