SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/Locales/LocaleInfoIND.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers\Locales;
  15.  
  16.  
  17. /**
  18.  * Locale info for India; see {@see LocaleInfo}
  19.  */
  20. class LocaleInfoIND extends LocaleInfo
  21. {
  22. protected $state_name = 'State';
  23. protected $state_list = array(
  24. 'Andaman and Nicobar Islands',
  25. 'Andhra Pradesh',
  26. 'Arunachal Pradesh',
  27. 'Assam',
  28. 'Bihar',
  29. 'Chandigarh',
  30. 'Chhattisgarh',
  31. 'Dadra and Nagar Haveli',
  32. 'Daman and Diu',
  33. 'Goa',
  34. 'Gujarat',
  35. 'Haryana',
  36. 'Himachal Pradesh',
  37. 'Jammu and Kashmir',
  38. 'Jharkhand',
  39. 'Karnataka',
  40. 'Kerala',
  41. 'Lakshadweep',
  42. 'Madhya Pradesh',
  43. 'Maharashtra',
  44. 'Manipur',
  45. 'Meghalaya',
  46. 'Mizoram',
  47. 'Nagaland',
  48. 'National Capital Territory of Delhi',
  49. 'Orissa',
  50. 'Puducherry',
  51. 'Punjab',
  52. 'Rajasthan',
  53. 'Sikkim',
  54. 'Tamil Nadu',
  55. 'Tripura',
  56. 'Uttarakhand',
  57. 'Uttar Pradesh',
  58. 'West Bengal',
  59. );
  60.  
  61. protected $town_name = 'Suburban area and City name';
  62.  
  63. protected $postcode_name = 'Postal Index Number';
  64.  
  65. protected $currency_symbol = 'Rs.';
  66. protected $currency_decimal = 0;
  67. protected $currency_name = 'Indian Rupee';
  68.  
  69.  
  70. /**
  71.   * India uses a number formatting system where the first group is three digits,
  72.   * and every subsequent group is two digits.
  73.   * @param int|float The number to format
  74.   * @param int $places The number of decimal places to render
  75.   * @return string
  76.   */
  77. public function numberFormat($number, $places = 0)
  78. {
  79. $matches = null;
  80. $parts = array();
  81. $offset = 0;
  82.  
  83. $number = round($number, $places);
  84. list($number, $dec) = sscanf($number, '%d.%d');
  85. $dec = str_pad($dec, $places, '0');
  86.  
  87. $number = strrev($number);
  88. if (preg_match('/\d\d\d/', $number, $matches)) {
  89. $parts[] = $matches[0];
  90. $offset += 3;
  91. } else {
  92. return strrev($number) . ($dec ? '.' . $dec : '');
  93. }
  94.  
  95. while (true) {
  96. if (preg_match('/\d\d/', $number, $matches, 0, $offset)) {
  97. $parts[] = $matches[0];
  98. $offset += 2;
  99. } else {
  100. $part = substr($number, $offset);
  101. if ($part) $parts[] = $part;
  102. break;
  103. }
  104. }
  105.  
  106. $number = strrev(implode(',', $parts)) . ($dec ? '.' . $dec : '');
  107.  
  108. return $number;
  109. }
  110. }
  111.  
  112.  
  113.