55 *Date: 2024-04-25
66*********************************************************************************/
77using System . Collections . Generic ;
8- using System . Text . RegularExpressions ;
98namespace WooLocalization
109{
1110 public static class Localization
@@ -14,10 +13,22 @@ public static class Localization
1413 public static LocalizationData context ;
1514 private static LocalizationPref pref ;
1615 private static ILocalizationPrefRecorder recorder = new MixedRecorder ( ) ;
17- private static List < ILocalizationEventActor > handlers = new List < ILocalizationEventActor > ( ) ;
16+ private static List < ILocalizationEventBehavior > behaviors = new List < ILocalizationEventBehavior > ( ) ;
17+
18+ public static void AddBehavior ( ILocalizationEventBehavior behavior ) => behaviors . Add ( behavior ) ;
19+ public static void RemoveBehavior ( ILocalizationEventBehavior behavior ) => behaviors . Remove ( behavior ) ;
20+
21+ public static void ForceRefreshBehaviors ( )
22+ {
23+ for ( int i = 0 ; i < behaviors . Count ; i ++ )
24+ {
25+ var behavior = behaviors [ i ] ;
26+ behavior . SetActorsDirty ( ) ;
27+ behavior . OnLanguageChange ( ) ;
28+ }
29+ }
30+
1831
19- public static void AddHandler ( ILocalizationEventActor handler ) => handlers . Add ( handler ) ;
20- public static void RemoveHandler ( ILocalizationEventActor handler ) => handlers . Remove ( handler ) ;
2132 public static void SetRecorder ( ILocalizationPrefRecorder recorder )
2233 {
2334 ( Localization . recorder as MixedRecorder ) . Add ( recorder ) ;
@@ -42,9 +53,9 @@ public static void SetLocalizationType(string language)
4253 if ( Localization . language == language ) return ;
4354 pref . language = language ;
4455 recorder . Write ( pref ) ;
45- for ( int i = 0 ; i < handlers . Count ; i ++ )
56+ for ( int i = 0 ; i < behaviors . Count ; i ++ )
4657 {
47- var handler = handlers [ i ] ;
58+ var handler = behaviors [ i ] ;
4859 if ( handler == null ) continue ;
4960 handler . OnLanguageChange ( ) ;
5061 }
@@ -74,7 +85,7 @@ public static string GetLocalization(LocalizationData context, string language,
7485 if ( string . IsNullOrEmpty ( restult ) ) return key ;
7586
7687#if UNITY_EDITOR
77- var match = Regex . Matches ( restult , "{[0-9]*}" ) ;
88+ var match = System . Text . RegularExpressions . Regex . Matches ( restult , "{[0-9]*}" ) ;
7889 if ( match . Count != 0 && ( args == null || args . Length != match . Count ) )
7990 throw new System . Exception ( $ "Args Err \t \t { nameof ( language ) } :{ language } \t { nameof ( key ) } :{ key } \n { restult } ") ;
8091#endif
0 commit comments