mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	* add lint rule * update usages * stragglers * use dcm * formatting * test ci * Revert "test ci" This reverts commit 8f864c4e4d3a7ec1a7e820b1afb3e801f2e82bc5. * revert whitespace change
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:easy_localization/easy_localization.dart';
 | 
						|
import 'package:intl/message_format.dart';
 | 
						|
import 'package:flutter/material.dart';
 | 
						|
import 'package:immich_mobile/utils/debug_print.dart';
 | 
						|
 | 
						|
extension StringTranslateExtension on String {
 | 
						|
  String t({BuildContext? context, Map<String, Object>? args}) {
 | 
						|
    return _translateHelper(context, this, args);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
extension TextTranslateExtension on Text {
 | 
						|
  Text t({BuildContext? context, Map<String, Object>? args}) {
 | 
						|
    return Text(
 | 
						|
      _translateHelper(context, data ?? '', args),
 | 
						|
      key: key,
 | 
						|
      style: style,
 | 
						|
      strutStyle: strutStyle,
 | 
						|
      textAlign: textAlign,
 | 
						|
      textDirection: textDirection,
 | 
						|
      locale: locale,
 | 
						|
      softWrap: softWrap,
 | 
						|
      overflow: overflow,
 | 
						|
      textScaler: textScaler,
 | 
						|
      maxLines: maxLines,
 | 
						|
      semanticsLabel: semanticsLabel,
 | 
						|
      textWidthBasis: textWidthBasis,
 | 
						|
      textHeightBehavior: textHeightBehavior,
 | 
						|
    );
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
String _translateHelper(BuildContext? context, String key, [Map<String, Object>? args]) {
 | 
						|
  if (key.isEmpty) {
 | 
						|
    return '';
 | 
						|
  }
 | 
						|
  try {
 | 
						|
    final translatedMessage = key.tr(context: context);
 | 
						|
    return args != null
 | 
						|
        ? MessageFormat(translatedMessage, locale: Intl.defaultLocale ?? 'en').format(args)
 | 
						|
        : translatedMessage;
 | 
						|
  } catch (e) {
 | 
						|
    dPrint(() => 'Translation failed for key "$key". Error: $e');
 | 
						|
    return key;
 | 
						|
  }
 | 
						|
}
 |