الأحد، 7 مايو 2017

هل هناك طريقة ابسط لتعريب الوقت في لارافل ?

السلام عليكم ورحمة الله تعالى وبركاته

عندما بداة في استعمال لارفل تطلب مني الامر تعريب الوقت فقمت بانشاء دالة

وهي كالتالي

 public static function ReplaceTimeAgoToar($text)
{
    if(!empty($text))
    {
        $text = str_replace('ago', ' ', $text);
        $text = str_replace('1 second ', 'ثانية', $text);
        $text = str_replace('second ', 'ثانية', $text);
        $text = str_replace('seconds', 'ثانية', $text);
        $text = str_replace('1 minute ', 'دقيقة', $text);
        $text = str_replace('minute ', 'دقيقة', $text);
        $text = str_replace('minutes', 'دقيقة', $text);
        $text = str_replace('1 hour ', 'ساعة', $text);
        $text = str_replace('hour ', 'ساعة', $text);
        $text = str_replace('hours', 'ساعات', $text);
        $text = str_replace('1 day ', 'يوم', $text);
        $text = str_replace('day ', 'يوم', $text);
        $text = str_replace('days', 'أيام', $text);
        $text = str_replace('1 week ', 'اسبوع', $text);
        $text = str_replace('week ', 'اسابيع', $text);
        $text = str_replace('weeks', 'اسابيع', $text);
        $text = str_replace('1 month ', 'شهر', $text);
        $text = str_replace('month ', 'شهر', $text);
        $text = str_replace('months', 'شهر', $text);
        $text = str_replace('1 year ', 'سنة', $text);
        $text = str_replace('year ', 'سنة', $text);
        $text = str_replace('years', 'سنوات', $text);
    }
    return $text;
}

تم استدعها بهذه طريقة



ولمن يستعمل تعدد اللغات هناك عدة اختيارات كاظافة شرط تحقق في دالة اعلاه او كما فعلت انا بالذهاب الى ملف Carbon وتعديل عليه

$return = static::translator()->trans($transId, array(':time' => $time));
    if (\App::isLocale('ar')) {
        $return = \Acogs::ReplaceTimeAgoToar($return);
    } 
    return $return;

هذا مافعلته هنا لكن غير مقتنع بها لذلك اسئل اذ في طريقة افضل ومختصرة اكثر رجاء

"نشرة طريقتي ربما قد تفيد غيري"



from حسوب I/O - الأكثر شيوعاً http://ift.tt/2pWgbRE

ليست هناك تعليقات:

إرسال تعليق

دائماً، رأيكم يهمنا،