forked from MapComplete/MapComplete
		
	UX: fix #1829
This commit is contained in:
		
							parent
							
								
									940f187041
								
							
						
					
					
						commit
						040e0fd8bf
					
				
					 2 changed files with 49 additions and 20 deletions
				
			
		|  | @ -852,7 +852,7 @@ class CheckTranslation extends DesugaringStep<Translatable> { | ||||||
|         for (const key of keys) { |         for (const key of keys) { | ||||||
|             const lng = json[key] |             const lng = json[key] | ||||||
|             if (lng === "") { |             if (lng === "") { | ||||||
|                 context.enter(lng).err("Got an empty string in translation for language " + lng) |                 context.enter(lng).err("Got an empty string in translation for language " + key) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // TODO validate that all subparts are here
 |             // TODO validate that all subparts are here
 | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
|   import LanguageUtils from "../../../Utils/LanguageUtils" |   import LanguageUtils from "../../../Utils/LanguageUtils" | ||||||
|   import { createEventDispatcher, onDestroy } from "svelte" |   import { createEventDispatcher, onDestroy } from "svelte" | ||||||
|   import ValidatedInput from "../ValidatedInput.svelte" |   import ValidatedInput from "../ValidatedInput.svelte" | ||||||
|  |   import { del } from "idb-keyval" | ||||||
| 
 | 
 | ||||||
|   export let value: UIEventSource<Record<string, string>> = new UIEventSource< |   export let value: UIEventSource<Record<string, string>> = new UIEventSource< | ||||||
|     Record<string, string> |     Record<string, string> | ||||||
|  | @ -18,14 +19,25 @@ | ||||||
|   const allLanguages: string[] = LanguageUtils.usedLanguagesSorted |   const allLanguages: string[] = LanguageUtils.usedLanguagesSorted | ||||||
|   let currentLang = new UIEventSource("en") |   let currentLang = new UIEventSource("en") | ||||||
|   const currentVal = new UIEventSource<string>("") |   const currentVal = new UIEventSource<string>("") | ||||||
|  |   /** | ||||||
|  |    * Mostly the same as currentVal, but might be the empty string as well | ||||||
|  |    */ | ||||||
|  |   const currentValRaw = new UIEventSource<string>("") | ||||||
|  | 
 | ||||||
|   let dispatch = createEventDispatcher<{ submit }>() |   let dispatch = createEventDispatcher<{ submit }>() | ||||||
| 
 | 
 | ||||||
|   function update() { |   function update() { | ||||||
|     const v = currentVal.data |     let v = currentValRaw.data | ||||||
|     const l = currentLang.data |     const l = currentLang.data | ||||||
|  |     console.log("Updating translation input for value", v, " and language", l) | ||||||
|     if (<any>translations.data === "" || translations.data === undefined) { |     if (<any>translations.data === "" || translations.data === undefined) { | ||||||
|       translations.data = {} |       translations.data = {} | ||||||
|     } |     } | ||||||
|  |     if (v === "") { | ||||||
|  |       delete translations.data[l] | ||||||
|  |       translations.ping() | ||||||
|  |       return | ||||||
|  |     } | ||||||
|     if (translations.data[l] === v) { |     if (translations.data[l] === v) { | ||||||
|       return |       return | ||||||
|     } |     } | ||||||
|  | @ -39,17 +51,22 @@ | ||||||
|         translations.data = {} |         translations.data = {} | ||||||
|       } |       } | ||||||
|       translations.data[currentLang] = translations.data[currentLang] ?? "" |       translations.data[currentLang] = translations.data[currentLang] ?? "" | ||||||
|       currentVal.setData(translations.data[currentLang]) |       if (translations.data[currentLang] === "") { | ||||||
|  |         delete translations.data[currentLang] | ||||||
|  |       } | ||||||
|  |       currentVal.setData(translations.data[currentLang] ?? "") | ||||||
|  |       currentValRaw.setData(translations.data[currentLang]) | ||||||
|     }) |     }) | ||||||
|   ) |   ) | ||||||
| 
 | 
 | ||||||
|   onDestroy( |   onDestroy( | ||||||
|     currentVal.addCallbackAndRunD(() => { |     currentValRaw.addCallbackAndRunD(() => { | ||||||
|       update() |       update() | ||||||
|     }) |     }) | ||||||
|   ) |   ) | ||||||
| </script> |  | ||||||
| 
 | 
 | ||||||
|  | </script> | ||||||
|  | <div class="flex flex-col gap-y-1"> | ||||||
|   <div class="interactive m-1 mt-2 flex space-x-1 font-bold"> |   <div class="interactive m-1 mt-2 flex space-x-1 font-bold"> | ||||||
|   <span> |   <span> | ||||||
|     {prefix} |     {prefix} | ||||||
|  | @ -58,6 +75,9 @@ | ||||||
|       {#each allLanguages as language} |       {#each allLanguages as language} | ||||||
|         <option value={language}> |         <option value={language}> | ||||||
|           {language} |           {language} | ||||||
|  |           {#if $translations[language] !== undefined} | ||||||
|  |             * | ||||||
|  |           {/if} | ||||||
|         </option> |         </option> | ||||||
|       {/each} |       {/each} | ||||||
|     </select> |     </select> | ||||||
|  | @ -65,9 +85,18 @@ | ||||||
|       type="string" |       type="string" | ||||||
|       cls="w-full" |       cls="w-full" | ||||||
|       value={currentVal} |       value={currentVal} | ||||||
|  |       unvalidatedText={currentValRaw} | ||||||
|       on:submit={() => dispatch("submit")} |       on:submit={() => dispatch("submit")} | ||||||
|     /> |     /> | ||||||
|     <span> |     <span> | ||||||
|     {postfix} |     {postfix} | ||||||
|   </span> |   </span> | ||||||
|  | 
 | ||||||
|  |   </div> | ||||||
|  |   You have currently set translations for | ||||||
|  |   <ul> | ||||||
|  |     {#each Object.keys($translations) as l} | ||||||
|  |       <li><button class="small" on:click={() => currentLang.setData(l)}><b>{l}:</b> {$translations[l]}</button></li> | ||||||
|  |     {/each} | ||||||
|  |   </ul> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue