@@ -462,6 +462,120 @@ public function testTransChoiceFallbackWithNoTranslation()
462
462
// unchanged if it can't be found
463
463
$ this ->assertEquals ('some_message2 ' , $ translator ->transChoice ('some_message2 ' , 10 , array ('%count% ' => 10 )));
464
464
}
465
+
466
+ /**
467
+ * @dataProvider dataProviderGetMessages
468
+ */
469
+ public function testGetMessages ($ resources , $ locale , $ expected )
470
+ {
471
+ $ locales = array_keys ($ resources );
472
+ $ _locale = !is_null ($ locale ) ? $ locale : reset ($ locales );
473
+ $ locales = array_slice ($ locales , 0 , array_search ($ _locale , $ locales ));
474
+
475
+ $ translator = new Translator ($ _locale , new MessageSelector ());
476
+ $ translator ->setFallbackLocales (array_reverse ($ locales ));
477
+ $ translator ->addLoader ('array ' , new ArrayLoader ());
478
+ foreach ($ resources as $ _locale => $ domainMessages ) {
479
+ foreach ($ domainMessages as $ domain => $ messages ) {
480
+ $ translator ->addResource ('array ' , $ messages , $ _locale , $ domain );
481
+ }
482
+ }
483
+ $ result = $ translator ->getMessages ($ locale );
484
+
485
+ $ this ->assertEquals ($ expected , $ result );
486
+ }
487
+
488
+ public function dataProviderGetMessages ()
489
+ {
490
+ $ resources = array (
491
+ 'en ' => array (
492
+ 'jsmessages ' => array (
493
+ 'foo ' => 'foo (EN) ' ,
494
+ 'bar ' => 'bar (EN) ' ,
495
+ ),
496
+ 'messages ' => array (
497
+ 'foo ' => 'foo messages (EN) ' ,
498
+ ),
499
+ 'validators ' => array (
500
+ 'int ' => 'integer (EN) ' ,
501
+ ),
502
+ ),
503
+ 'pt-PT ' => array (
504
+ 'messages ' => array (
505
+ 'foo ' => 'foo messages (PT) ' ,
506
+ ),
507
+ 'validators ' => array (
508
+ 'str ' => 'integer (PT) ' ,
509
+ ),
510
+ ),
511
+ 'pt_BR ' => array (
512
+ 'validators ' => array (
513
+ 'int ' => 'integer (BR) ' ,
514
+ ),
515
+ ),
516
+ );
517
+
518
+ return array (
519
+ array ($ resources , null ,
520
+ array (
521
+ 'jsmessages ' => array (
522
+ 'foo ' => 'foo (EN) ' ,
523
+ 'bar ' => 'bar (EN) ' ,
524
+ ),
525
+ 'messages ' => array (
526
+ 'foo ' => 'foo messages (EN) ' ,
527
+ ),
528
+ 'validators ' => array (
529
+ 'int ' => 'integer (EN) ' ,
530
+ ),
531
+ ),
532
+ ),
533
+ array ($ resources , 'en ' ,
534
+ array (
535
+ 'jsmessages ' => array (
536
+ 'foo ' => 'foo (EN) ' ,
537
+ 'bar ' => 'bar (EN) ' ,
538
+ ),
539
+ 'messages ' => array (
540
+ 'foo ' => 'foo messages (EN) ' ,
541
+ ),
542
+ 'validators ' => array (
543
+ 'int ' => 'integer (EN) ' ,
544
+ ),
545
+ ),
546
+ ),
547
+ array ($ resources , 'pt-PT ' ,
548
+ array (
549
+ 'jsmessages ' => array (
550
+ 'foo ' => 'foo (EN) ' ,
551
+ 'bar ' => 'bar (EN) ' ,
552
+ ),
553
+ 'messages ' => array (
554
+ 'foo ' => 'foo messages (PT) ' ,
555
+ ),
556
+ 'validators ' => array (
557
+ 'int ' => 'integer (EN) ' ,
558
+ 'str ' => 'integer (PT) ' ,
559
+ ),
560
+ ),
561
+ ),
562
+ array ($ resources , 'pt_BR ' ,
563
+ array (
564
+ 'jsmessages ' => array (
565
+ 'foo ' => 'foo (EN) ' ,
566
+ 'bar ' => 'bar (EN) ' ,
567
+ ),
568
+ 'messages ' => array (
569
+ 'foo ' => 'foo messages (PT) ' ,
570
+ ),
571
+ 'validators ' => array (
572
+ 'int ' => 'integer (BR) ' ,
573
+ 'str ' => 'integer (PT) ' ,
574
+ ),
575
+ ),
576
+ ),
577
+ );
578
+ }
465
579
}
466
580
467
581
class String
0 commit comments