| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import { VariableUiElement } from "./VariableUIElement" | 
					
						
							|  |  |  | import Locale from "../i18n/Locale" | 
					
						
							|  |  |  | import Link from "./Link" | 
					
						
							|  |  |  | import Svg from "../../Svg" | 
					
						
							| 
									
										
										
										
											2022-04-01 12:51:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-22 16:21:07 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * The little 'translate'-icon next to every icon + some static helper functions | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2022-04-01 12:51:55 +02:00
										 |  |  | export default class LinkToWeblate extends VariableUiElement { | 
					
						
							|  |  |  |     constructor(context: string, availableTranslations: object) { | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         super( | 
					
						
							|  |  |  |             Locale.language.map( | 
					
						
							|  |  |  |                 (ln) => { | 
					
						
							|  |  |  |                     if (Locale.showLinkToWeblate.data === false) { | 
					
						
							|  |  |  |                         return undefined | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     if (availableTranslations["*"] !== undefined) { | 
					
						
							|  |  |  |                         return undefined | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     if (context === undefined || context.indexOf(":") < 0) { | 
					
						
							|  |  |  |                         return undefined | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     const icon = Svg.translate_svg().SetClass( | 
					
						
							|  |  |  |                         "rounded-full border border-gray-400 inline-block w-4 h-4 m-1 weblate-link self-center" | 
					
						
							|  |  |  |                     ) | 
					
						
							|  |  |  |                     if (availableTranslations[ln] === undefined) { | 
					
						
							|  |  |  |                         icon.SetClass("bg-red-400") | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     return new Link(icon, LinkToWeblate.hrefToWeblate(ln, context), true) | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 [Locale.showLinkToWeblate] | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-04-01 12:51:55 +02:00
										 |  |  |         this.SetClass("enable-links hidden-on-mobile") | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-04 14:23:19 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Creates the url to Hosted weblate | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * LinkToWeblate.hrefToWeblate("nl", "category:some.context") // => "https://hosted.weblate.org/translate/mapcomplete/category/nl/?offset=1&q=context%3A%3D%22some.context%22"
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public static hrefToWeblate(language: string, contextKey: string): string { | 
					
						
							|  |  |  |         if (contextKey === undefined || contextKey.indexOf(":") < 0) { | 
					
						
							| 
									
										
										
										
											2022-04-03 23:42:35 +02:00
										 |  |  |             return undefined | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-04-01 12:51:55 +02:00
										 |  |  |         const [category, ...rest] = contextKey.split(":") | 
					
						
							|  |  |  |         const key = rest.join(":") | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 12:51:55 +02:00
										 |  |  |         const baseUrl = "https://hosted.weblate.org/translate/mapcomplete/" | 
					
						
							|  |  |  |         return baseUrl + category + "/" + language + "/?offset=1&q=context%3A%3D%22" + key + "%22" | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-04-15 00:10:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     public static hrefToWeblateZen( | 
					
						
							|  |  |  |         language: string, | 
					
						
							|  |  |  |         category: "core" | "themes" | "layers" | "shared-questions" | "glossary" | string, | 
					
						
							|  |  |  |         searchKey: string | 
					
						
							|  |  |  |     ): string { | 
					
						
							| 
									
										
										
										
											2022-04-15 00:10:04 +02:00
										 |  |  |         const baseUrl = "https://hosted.weblate.org/zen/mapcomplete/" | 
					
						
							|  |  |  |         // ?offset=1&q=+state%3A%3Ctranslated+context%3Acampersite&sort_by=-priority%2Cposition&checksum=
 | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |         return ( | 
					
						
							|  |  |  |             baseUrl + | 
					
						
							|  |  |  |             category + | 
					
						
							|  |  |  |             "/" + | 
					
						
							|  |  |  |             language + | 
					
						
							|  |  |  |             "?offset=1&q=+state%3A%3Ctranslated+context%3A" + | 
					
						
							|  |  |  |             encodeURIComponent(searchKey) + | 
					
						
							|  |  |  |             "&sort_by=-priority%2Cposition&checksum=" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2022-04-15 00:10:04 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | } |