@@ -16,6 +16,8 @@ import java.io.OutputStreamWriter
1616import java.text.SimpleDateFormat
1717import java.util.Date
1818import java.util.Locale
19+ import androidx.compose.ui.res.stringResource
20+ import com.mouton.openwinemer.R
1921
2022/* *
2123 * Cette classe gère :
@@ -54,12 +56,12 @@ class BackupUseCase(
5456
5557 // On accède au dossier choisi par l'utilisateur.
5658 val root = DocumentFile .fromTreeUri(context, treeUri)
57- ? : throw IllegalStateException (" Impossible d'accéder au dossier sélectionné. " )
59+ ? : throw IllegalStateException (context.getString( R .string.cant_access_folder) )
5860
5961 // On crée un fichier avec la date et l'heure dans le nom.
6062 val fileName = " openwinemer_backup_${currentTimestamp()} .json"
6163 val file = root.createFile(" application/json" , fileName)
62- ? : throw IllegalStateException (" Impossible de créer le fichier dans ce dossier. " )
64+ ? : throw IllegalStateException (context.getString( R .string.cant_create_here) )
6365
6466 // On écrit le contenu dans le fichier.
6567 context.contentResolver.openOutputStream(file.uri)?.use { out ->
@@ -72,7 +74,7 @@ class BackupUseCase(
7274 // ------------------------------------------------------------
7375 suspend fun importBackupFromUri (uri : Uri , password : String? ) {
7476 val inputStream = context.contentResolver.openInputStream(uri)
75- ? : throw IllegalStateException (" Impossible de lire le fichier sélectionné. " )
77+ ? : throw IllegalStateException (context.getString( R .string.cant_read_file) )
7678
7779 val content = inputStream.readBytes().decodeToString()
7880
@@ -85,7 +87,7 @@ class BackupUseCase(
8587 try {
8688 BackupCrypto .decrypt(content, password)
8789 } catch (e: Exception ) {
88- throw IllegalStateException (" Mot de passe incorrect ou fichier chiffré invalide " )
90+ throw IllegalStateException (context.getString( R .string.wrong_pwd_or_file) )
8991 }
9092 }
9193
@@ -97,7 +99,7 @@ class BackupUseCase(
9799 // Ici on tombe par exemple si :
98100 // - le fichier est chiffré mais password est vide
99101 // - le contenu n’est pas un JSON valide
100- throw IllegalStateException (" Fichier de sauvegarde invalide ou mot de passe incorrect " )
102+ throw IllegalStateException (context.getString( R .string.invalid_save_file) )
101103 }
102104
103105 // 3) Insérer en base
@@ -112,12 +114,12 @@ class BackupUseCase(
112114 val wines = wineDao.getAllWines().first()
113115
114116 val root = DocumentFile .fromTreeUri(context, treeUri)
115- ? : throw IllegalStateException (" Impossible d'accéder au dossier sélectionné. " )
117+ ? : throw IllegalStateException (context.getString( R .string.cant_access_folder) )
116118
117119 // Nom de fichier avec date et heure.
118120 val fileName = " openwinemer_export_${currentTimestamp()} .csv"
119121 val file = root.createFile(" text/csv" , fileName)
120- ? : throw IllegalStateException (" Impossible de créer le fichier CSV. " )
122+ ? : throw IllegalStateException (context.getString( R .string.cant_make_csv) )
121123
122124 context.contentResolver.openOutputStream(file.uri)?.use { out ->
123125 val writer = OutputStreamWriter (out )
0 commit comments