Skip to content

Commit ce29975

Browse files
committed
PathToLocale dictionary ordered by depth descending, based on count of forward slashes in path
1 parent 599bfb9 commit ce29975

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

core/Helpers/ApiHelper_Services.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public List<BaseTask> SystemTasks()
292292

293293
public String PathLocalisation(string path)
294294
{
295-
var meta = repo.GetPuckMeta().Where(x => x.Name == DBNames.PathToLocale && path.StartsWith(x.Key)).OrderByDescending(x => x.Key.Length).FirstOrDefault();
295+
var meta = repo.GetPuckMeta().Where(x => x.Name == DBNames.PathToLocale && (path+"/").StartsWith(x.Key+"/")).OrderByDescending(x => x.Key.Length).FirstOrDefault();
296296
return meta == null ? null : meta.Value;
297297
}
298298
public String DomainMapping(string path)

core/Helpers/StateHelper.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,17 @@ public static void UpdatePathLocaleMappings(bool addInstruction=false)
329329
using (var scope = PuckCache.ServiceProvider.CreateScope())
330330
{
331331
var repo = scope.ServiceProvider.GetService<I_Puck_Repository>();
332-
var meta = repo.GetPuckMeta().Where(x => x.Name == DBNames.PathToLocale).OrderByDescending(x => x.Key.Length).ToList();
332+
var meta = repo.GetPuckMeta()
333+
.Where(x => x.Name == DBNames.PathToLocale)
334+
.ToList()
335+
.Where(x=>!string.IsNullOrEmpty(x.Key))
336+
.OrderByDescending(x => x.Key.Count(xx => xx == '/'))
337+
.ToList();
338+
333339
var map = new Dictionary<string, string>();
334340
meta.ForEach(x =>
335341
{
336-
//map.Add(x.Key.ToLower(), x.Value.ToLower());
337-
map[x.Key.ToLower()] = x.Value.ToLower();
342+
map[x.Key.ToLower()] = x.Value.ToLower();
338343
});
339344
PuckCache.PathToLocale = map;
340345

0 commit comments

Comments
 (0)