<commit_before>package ufront.web.routing;
import ufront.web.routing.RouteCollection;
import ufront.web.HttpContext;
import ufront.web.mvc.MvcRouteHandler;
import thx.translation.ITranslation;
import thx.error.NullArgument;
import ufront.web.routing.IRouteHandler;
import ufront.web.routing.RouteUriParser;
import haxe.ds.StringMap;
using Hashes;
using DynamicsT;

class LocalizedRoute extends Route
{
	public var translator(default, null) : ITranslation;
	public var currentLanguage : String;
	public var paramName : String;
	public function new(translator : ITranslation, url : String, handler : IRouteHandler, ?defaults : StringMap<String>, ?constraints : Array<IRouteConstraint>)
	{
		super(url, handler, defaults, constraints);
		_asts = new StringMap();
		NullArgument.throwIfNull(translator);
		this.translator = translator;
		currentLanguage = null;
		paramName = "lang";
	}

	override function get_url()
	{
		if(null == currentLanguage)
			return super.get_url();
		else
			return translator._(super.get_url(), currentLanguage);
			// NEED TO CHECK WHAT THIS IS SUPPOSED TO BE...
			// return super.get_url();
	}

	var _asts : StringMap<UriSegments>;
	override function getAst()
	{
		var key = currentLanguage;
		if(null == key)
			key = "";
		var ast = _asts.get(key);
		if(null == ast)
		{
			ast = Route.parser.parse(url, defaults.setOfKeys());
			_asts.set(key, ast);
		}
		return ast;
	}

	override function getRouteData(httpContext : HttpContext) : RouteData
	{
  //  	trace("rule url: " + url + ", request: " + httpContext.request.uri + ", context: " + httpContext.getRequestUri() + ", query params: " + httpContext.request.query);
 //   	trace(httpContext.request.query);
		currentLanguage = httpContext.request.query.get(paramName);
		return super.getRouteData(httpContext);<commit_msg>Using `translator.singular` in place of old `translator._`<commit_after>package ufront.web.routing;
import ufront.web.routing.RouteCollection;
import ufront.web.HttpContext;
import ufront.web.mvc.MvcRouteHandler;
import thx.translation.ITranslation;
import thx.error.NullArgument;
import ufront.web.routing.IRouteHandler;
import ufront.web.routing.RouteUriParser;
import haxe.ds.StringMap;
using Hashes;
using DynamicsT;

class LocalizedRoute extends Route
{
	public var translator(default, null) : ITranslation;
	public var currentLanguage : String;
	public var paramName : String;
	public function new(translator : ITranslation, url : String, handler : IRouteHandler, ?defaults : StringMap<String>, ?constraints : Array<IRouteConstraint>)
	{
		super(url, handler, defaults, constraints);
		_asts = new StringMap();
		NullArgument.throwIfNull(translator);
		this.translator = translator;
		currentLanguage = null;
		paramName = "lang";
	}

	override function get_url()
	{
		if(null == currentLanguage)
			return super.get_url();
		else
			// NEED TO CHECK THAT THE UNCOMMENTED LINE IS EQUIVALENT TO THE COMMENTED LINE
			// return translator._(super.get_url(), currentLanguage);
			return translator.singular(super.get_url(), currentLanguage);
	}

	var _asts : StringMap<UriSegments>;
	override function getAst()
	{
		var key = currentLanguage;
		if(null == key)
			key = "";
		var ast = _asts.get(key);
		if(null == ast)
		{
			ast = Route.parser.parse(url, defaults.setOfKeys());
			_asts.set(key, ast);
		}
		return ast;
	}

	override function getRouteData(httpContext : HttpContext) : RouteData
	{
  //  	trace("rule url: " + url + ", request: " + httpContext.request.uri + ", context: " + httpContext.getRequestUri() + ", query params: " + httpContext.request.query);
 //   	trace(httpContext.request.query);
		currentLanguage = httpContext.request.query.get(paramName);
		return super.getRouteData(httpContext);
{'fraction_non_alphanumeric': 0.12063406770553466, 'fraction_numerical': 0.0, 'mean_word_length': 4.727692307692307, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4139874', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1163, 'n_words': 272}