mirror of
				https://framagit.org/tom79/fedilab-tube
				synced 2025-06-05 21:09:11 +02:00 
			
		
		
		
	Fix crashes
This commit is contained in:
		| @@ -543,10 +543,14 @@ public class RetrofitPeertubeAPI { | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         String lang = null; | ||||
|         if (PeertubeInformation.langueMapped.containsKey(Locale.getDefault().getLanguage())) | ||||
|             lang = PeertubeInformation.langueMapped.get(Locale.getDefault().getLanguage()); | ||||
|  | ||||
|         String lang = Locale.getDefault().getLanguage(); | ||||
|         if( lang.contains("-")) { | ||||
|             if( !lang.split("-")[0].trim().toLowerCase().startsWith("zh")){ | ||||
|                 lang = lang.split("-")[0]; | ||||
|             }else { | ||||
|                 lang = lang.split("-")[0] + "-" + lang.split("-")[1].toUpperCase(); | ||||
|             } | ||||
|         } | ||||
|         Call<Map<String, String>> translations = initTranslation().getTranslations(lang); | ||||
|         try { | ||||
|             Response<Map<String, String>> response = translations.execute(); | ||||
| @@ -556,7 +560,23 @@ public class RetrofitPeertubeAPI { | ||||
|                 Error error = new Error(); | ||||
|                 error.setStatusCode(response.code()); | ||||
|                 if (response.errorBody() != null) { | ||||
|                     error.setError(response.errorBody().string()); | ||||
|                     translations = initTranslation().getTranslations("en"); | ||||
|                     try { | ||||
|                         response = translations.execute(); | ||||
|                         if (response.isSuccessful()) { | ||||
|                             peertubeInformation.setTranslations(response.body()); | ||||
|                         } else { | ||||
|                             error = new Error(); | ||||
|                             error.setStatusCode(response.code()); | ||||
|                             if (response.errorBody() != null) { | ||||
|                                 error.setError(response.errorBody().string()); | ||||
|                             } else { | ||||
|                                 error.setError(_context.getString(R.string.toast_error)); | ||||
|                             } | ||||
|                         } | ||||
|                     } catch (IOException e) { | ||||
|                         e.printStackTrace(); | ||||
|                     } | ||||
|                 } else { | ||||
|                     error.setError(_context.getString(R.string.toast_error)); | ||||
|                 } | ||||
|   | ||||
| @@ -14,33 +14,11 @@ package app.fedilab.fedilabtube.client.entities; | ||||
|  * You should have received a copy of the GNU General Public License along with TubeLab; if not, | ||||
|  * see <http://www.gnu.org/licenses>. */ | ||||
|  | ||||
| import java.util.LinkedHashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
|  | ||||
| public class PeertubeInformation { | ||||
|  | ||||
|  | ||||
|     public static final Map<String, String> langueMapped; | ||||
|  | ||||
|     static { | ||||
|         Map<String, String> aMap = new LinkedHashMap<>(); | ||||
|         aMap.put("ca", "ca-ES"); | ||||
|         aMap.put("de", "de-DE"); | ||||
|         aMap.put("en", "en-US"); | ||||
|         aMap.put("es", "es-ES"); | ||||
|         aMap.put("eo", "eo"); | ||||
|         aMap.put("eu", "eu-ES"); | ||||
|         aMap.put("fr", "fr-FR"); | ||||
|         aMap.put("oc", "oc"); | ||||
|         aMap.put("pt", "pt-BR"); | ||||
|         aMap.put("sv", "sv-SE"); | ||||
|         aMap.put("cs", "cs-CZ"); | ||||
|         aMap.put("zh-CN", "zh-Hans-CN"); | ||||
|         aMap.put("zh-TW", "zh-Hans-TW"); | ||||
|         langueMapped = aMap; | ||||
|     } | ||||
|  | ||||
|     private Map<Integer, String> categories; | ||||
|     private Map<String, String> languages; | ||||
|     private Map<Integer, String> licences; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user