XF 1.3 How to use Arabic digits instead of English digits.

Barbossa

Active member
Hi,
I am translating phrases into Arabic. So far there is no problem. Now, How can I change digits into Arabic?

I mean,

0 as ۰
1 as ۱
2 as ۲
3 as ۳
4 as ۴
5 as ۵
6 as ۶
7 as ۷
8 as ۸
9 as ۹

For example, I am asking to change those digits into Arabic.
 

Attachments

  • digit.webp
    digit.webp
    78.2 KB · Views: 30
Google says you need to do a str_replace:

http://stackoverflow.com/questions/3386835/convert-english-numbers-to-arabic-numerals

So...

library/XenForo/Locale.php

Add the red code:

Rich (BB code):
	/**
	 * Formats the given number for a language/locale. Also used for file size formatting.
	 *
	 * @param float|integer $number Number to format
	 * @param integer|string $precision Number of places to show after decimal point or word "size" for file size
	 * @param array|null $language Language to override default
	 *
	 * @return string Formatted number
	 */
	public static function numberFormat($number, $precision = 0, array $language = null)
	{
		if (!$language)
		{
			$language = self::$_language;
		}

		if (!$language)
		{
			$decimalSep = '.';
			$thousandsSep = ',';
		}
		else
		{
			$decimalSep = $language['decimal_point'];
			$thousandsSep = $language['thousands_separator'];
		}

		if ($precision === 'size')
		{
			if ($number >= 1099511627776) // 1 TB
			{
				$number = number_format($number / 1099511627776, 1, $decimalSep, $thousandsSep);
				$unit = ' TB';
				$phrase = 'x_tb';
			}
			else if ($number >= 1073741824) // 1 GB
			{
				$number = number_format($number / 1073741824, 1, $decimalSep, $thousandsSep);
				$unit = ' GB';
				$phrase = 'x_gb';
			}
			else if ($number >= 1048576) // 1 MB
			{
				$number = number_format($number / 1048576, 1, $decimalSep, $thousandsSep);
				$unit = ' MB';
				$phrase = 'x_mb';
			}
			else if ($number >= 1024) // 1 KB
			{
				$number = number_format($number / 1024, 1, $decimalSep, $thousandsSep);
				$unit = ' KB';
				$phrase = 'x_kb';
			}
			else
			{
				$number = number_format($number, 1, $decimalSep, $thousandsSep);
				$unit = ' bytes';
				$phrase = 'x_bytes';
			}

			// return $number, not $number.0 when the decimal is 0.
			if (substr($number, -2) == $decimalSep . '0')
			{
				$number = substr($number, 0, -2);
			}

			if (!$language || !isset($language['phrase_cache'][$phrase]))
			{
				return $number . $unit;
			}
			else
			{
				return str_replace('{size}', $number, $language['phrase_cache'][$phrase]);
			}
		}
		else
		{
			// return number_format($number, $precision, $decimalSep, $thousandsSep);

			$retval = number_format($number, $precision, $decimalSep, $thousandsSep);

			$standard = array("0","1","2","3","4","5","6","7","8","9");
			$east_arabic = array("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩");

			return str_replace($standard , $east_arabic , $retval);
		}
	}

This appears to work in my testing.
 
Back
Top Bottom