forked from MapComplete/MapComplete
		
	Fix: fix translation links
This commit is contained in:
		
							parent
							
								
									8b1873479d
								
							
						
					
					
						commit
						8fc31fcd9d
					
				
					 2 changed files with 33 additions and 24 deletions
				
			
		|  | @ -37,10 +37,8 @@ import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable" | ||||||
| import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers" | import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers" | ||||||
| import { ExtractImages } from "../src/Models/ThemeConfig/Conversion/FixImages" | import { ExtractImages } from "../src/Models/ThemeConfig/Conversion/FixImages" | ||||||
| import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson" | import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson" | ||||||
| import { | import { LayerConfigDependencyGraph, LevelInfo } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph" | ||||||
|     LayerConfigDependencyGraph, | import { AddContextToTranslations } from "../src/Models/ThemeConfig/Conversion/AddContextToTranslations" | ||||||
|     LevelInfo, |  | ||||||
| } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph" |  | ||||||
| 
 | 
 | ||||||
| // This scripts scans 'src/assets/layers/*.json' for layer definition files and 'src/assets/themes/*.json' for theme definition files.
 | // This scripts scans 'src/assets/layers/*.json' for layer definition files and 'src/assets/themes/*.json' for theme definition files.
 | ||||||
| // It spits out an overview of those to be used to load them
 | // It spits out an overview of those to be used to load them
 | ||||||
|  | @ -224,9 +222,16 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> { | ||||||
|             context.err("Invalid ID: expected", id, "but got", id) |             context.err("Invalid ID: expected", id, "but got", id) | ||||||
|         } |         } | ||||||
|         const prepped = this.prepareLayer.convert(config, context) |         const prepped = this.prepareLayer.convert(config, context) | ||||||
|  |         const withContext = new AddContextToTranslations<LayerConfigJson>("layers:").convertStrict( | ||||||
|  |             prepped, | ||||||
|  |             ConversionContext.construct( | ||||||
|  |                 [prepped.id], | ||||||
|  |                 ["AddContextToTranslations"] | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|         this._loadedIds.add(id) |         this._loadedIds.add(id) | ||||||
|         this._desugaringState.sharedLayers.set(id, prepped) |         this._desugaringState.sharedLayers.set(id, withContext) | ||||||
|         return prepped |         return withContext | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private buildLooping(ids: string[], context: ConversionContext) { |     private buildLooping(ids: string[], context: ConversionContext) { | ||||||
|  | @ -690,8 +695,8 @@ class LayerOverviewUtils extends Script { | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         const path = "assets/layers/questions/questions.json" |         const path = "assets/layers/questions/questions.json" | ||||||
|         const sharedQuestions = this.parseLayer(doesImageExist, prepareLayer, path).raw |         const sharedQuestionsRaw = this.parseLayer(doesImageExist, prepareLayer, path).raw | ||||||
| 
 |         const sharedQuestions = new AddContextToTranslations("").convertStrict(sharedQuestionsRaw, ConversionContext.construct(["layers:questions"], [])) | ||||||
|         const dict = new Map<string, QuestionableTagRenderingConfigJson>() |         const dict = new Map<string, QuestionableTagRenderingConfigJson>() | ||||||
| 
 | 
 | ||||||
|         for (const tr of sharedQuestions.tagRenderings) { |         for (const tr of sharedQuestions.tagRenderings) { | ||||||
|  |  | ||||||
|  | @ -128,24 +128,28 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> { | ||||||
|                 if (leaf === undefined || leaf === null) { |                 if (leaf === undefined || leaf === null) { | ||||||
|                     return leaf |                     return leaf | ||||||
|                 } |                 } | ||||||
|                 if (typeof leaf === "object") { |                 if (typeof leaf !== "object") { | ||||||
|                     // follow the path. If we encounter a number, check that there is no ID we can use instead
 |  | ||||||
|                     let breadcrumb = json |  | ||||||
|                     for (let i = 0; i < path.length; i++) { |  | ||||||
|                         const pointer = path[i] |  | ||||||
|                         breadcrumb = breadcrumb[pointer] |  | ||||||
|                         if (pointer.match("[0-9]+") && breadcrumb["id"] !== undefined) { |  | ||||||
|                             path[i] = breadcrumb["id"] |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     return { |  | ||||||
|                         ...leaf, |  | ||||||
|                         _context: this._prefix + context.path.concat(path).join("."), |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     return leaf |                     return leaf | ||||||
|                 } |                 } | ||||||
|  |                 if(leaf["_context"] !== undefined){ | ||||||
|  |                     // Context is already set
 | ||||||
|  |                     return leaf | ||||||
|  |                 } | ||||||
|  |                 // follow the path. If we encounter a number, check that there is no ID we can use instead
 | ||||||
|  |                 let breadcrumb = json | ||||||
|  |                 for (let i = 0; i < path.length; i++) { | ||||||
|  |                     const pointer = path[i] | ||||||
|  |                     breadcrumb = breadcrumb[pointer] | ||||||
|  |                     if (pointer.match("[0-9]+") && breadcrumb["id"] !== undefined) { | ||||||
|  |                         path[i] = breadcrumb["id"] | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 const pth = this._prefix + Utils.NoEmpty(context.path.concat(path).map(x => "" + x)).join(".") | ||||||
|  |                 console.log("Setting _context to: ",pth) | ||||||
|  |                 return { | ||||||
|  |                     ...leaf, | ||||||
|  |                     _context: pth, | ||||||
|  |                 } | ||||||
|             }, |             }, | ||||||
|             (obj) => obj === undefined || obj === null || Translations.isProbablyATranslation(obj) |             (obj) => obj === undefined || obj === null || Translations.isProbablyATranslation(obj) | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue