├── .gitattributes ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Controllers └── HomeController.cs ├── LanguageSwitcherTagHelper.csproj ├── LanguageSwitcherTagHelper.sln ├── Program.cs ├── Properties └── launchSettings.json ├── README.md ├── Resources.Designer.cs ├── Resources.resx ├── Startup.cs ├── TagHelpers ├── DisplayMode.cs ├── LanguageSwitcherTagHelper.cs └── LanguageSwitcherTagHelperComponent.cs ├── Views ├── Home │ ├── About.cshtml │ └── Index.cshtml ├── Shared │ ├── Error.cshtml │ ├── _Layout.cshtml │ ├── _LoginPartial.cshtml │ └── _ValidationScriptsPartial.cshtml ├── _ViewImports.cshtml └── _ViewStart.cshtml ├── project.json ├── web.config └── wwwroot ├── _references.js ├── css ├── site.css └── site.min.css ├── favicon.ico ├── images ├── ASP-NET-Banners-01.png ├── ASP-NET-Banners-02.png ├── Banner-01-Azure.png ├── Banner-02-VS.png ├── ar-sa.png ├── ar-ye.png ├── en-US.png ├── es.png └── fr.png ├── js ├── site.js └── site.min.js └── lib ├── bootstrap ├── .bower.json ├── LICENSE └── dist │ ├── css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap.css │ ├── bootstrap.css.map │ └── bootstrap.min.css │ ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 │ └── js │ ├── bootstrap.js │ ├── bootstrap.min.js │ └── npm.js ├── jquery-validation-unobtrusive ├── .bower.json ├── jquery.validate.unobtrusive.js └── jquery.validate.unobtrusive.min.js ├── jquery-validation ├── .bower.json ├── LICENSE.md └── dist │ ├── additional-methods.js │ ├── additional-methods.min.js │ ├── jquery.validate.js │ └── jquery.validate.min.js └── jquery ├── .bower.json ├── MIT-LICENSE.txt └── dist ├── jquery.js ├── jquery.min.js └── jquery.min.map /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Make sh files under the build directory always have LF as line endings 8 | ############################################################################### 9 | build/*.sh eol=lf 10 | 11 | 12 | ############################################################################### 13 | # Set default behavior for command prompt diff. 14 | # 15 | # This is need for earlier builds of msysgit that does not have it on by 16 | # default for csharp files. 17 | # Note: This is only used by command line 18 | ############################################################################### 19 | #*.cs diff=csharp 20 | 21 | ############################################################################### 22 | # Set the merge driver for project and solution files 23 | # 24 | # Merging from the command prompt will add diff markers to the files if there 25 | # are conflicts (Merging from VS is not affected by the settings below, in VS 26 | # the diff markers are never inserted). Diff markers may cause the following 27 | # file extensions to fail to load in VS. An alternative would be to treat 28 | # these files as binary and thus will always conflict and require user 29 | # intervention with every merge. To do so, just uncomment the entries below 30 | ############################################################################### 31 | #*.sln merge=binary 32 | #*.csproj merge=binary 33 | #*.vbproj merge=binary 34 | #*.vcxproj merge=binary 35 | #*.vcproj merge=binary 36 | #*.dbproj merge=binary 37 | #*.fsproj merge=binary 38 | #*.lsproj merge=binary 39 | #*.wixproj merge=binary 40 | #*.modelproj merge=binary 41 | #*.sqlproj merge=binary 42 | #*.wwaproj merge=binary 43 | 44 | ############################################################################### 45 | # behavior for image files 46 | # 47 | # image files are treated as binary by default. 48 | ############################################################################### 49 | #*.jpg binary 50 | #*.png binary 51 | #*.gif binary 52 | 53 | ############################################################################### 54 | # diff behavior for common document formats 55 | # 56 | # Convert binary document formats to text before diffing them. This feature 57 | # is only available from the command line. Turn it on by uncommenting the 58 | # entries below. 59 | ############################################################################### 60 | #*.doc diff=astextplain 61 | #*.DOC diff=astextplain 62 | #*.docx diff=astextplain 63 | #*.DOCX diff=astextplain 64 | #*.dot diff=astextplain 65 | #*.DOT diff=astextplain 66 | #*.pdf diff=astextplain 67 | #*.PDF diff=astextplain 68 | #*.rtf diff=astextplain 69 | #*.RTF diff=astextplain 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | *.suo 4 | *.user 5 | _ReSharper.* 6 | *.DS_Store 7 | *.userprefs 8 | *.pidb 9 | *.vspx 10 | *.psess 11 | packages 12 | target 13 | artifacts 14 | StyleCop.Cache 15 | node_modules 16 | *.snk 17 | .nuget/NuGet.exe 18 | project.lock.json -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": ".NET Core Launch (console)", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/HelloMvc.dll", 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "stopAtEntry": false 13 | }, 14 | { 15 | "name": ".NET Core Launch (web)", 16 | "type": "coreclr", 17 | "request": "launch", 18 | "preLaunchTask": "build", 19 | "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/HelloMvc.dll", 20 | "args": [], 21 | "cwd": "${workspaceRoot}", 22 | "stopAtEntry": false, 23 | "launchBrowser": { 24 | "enabled": true, 25 | "args": "${auto-detect-url}", 26 | "windows": { 27 | "command": "cmd.exe", 28 | "args": "/C start ${auto-detect-url}" 29 | }, 30 | "osx": { 31 | "command": "open" 32 | }, 33 | "linux": { 34 | "command": "xdg-open" 35 | } 36 | } 37 | }, 38 | { 39 | "name": ".NET Core Attach", 40 | "type": "coreclr", 41 | "request": "attach", 42 | "processName": "" 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "dotnet", 4 | "isShellCommand": true, 5 | "args": [], 6 | "tasks": [ 7 | { 8 | "taskName": "build", 9 | "args": [], 10 | "isBuildCommand": true, 11 | "problemMatcher": "$msCompile" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace LanguageSwitcherTagHelper 4 | { 5 | public class HomeController : Controller 6 | { 7 | [HttpGet("/")] 8 | public IActionResult Index() => View(); 9 | 10 | [HttpGet("/About")] 11 | public IActionResult About() => View(); 12 | } 13 | } -------------------------------------------------------------------------------- /LanguageSwitcherTagHelper.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LanguageSwitcherTagHelper.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26228.4 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LanguageSwitcherTagHelper", "LanguageSwitcherTagHelper.csproj", "{374B2D71-B573-4518-8C41-A7A500FB931D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {374B2D71-B573-4518-8C41-A7A500FB931D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {374B2D71-B573-4518-8C41-A7A500FB931D}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {374B2D71-B573-4518-8C41-A7A500FB931D}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {374B2D71-B573-4518-8C41-A7A500FB931D}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace LanguageSwitcherTagHelper 7 | { 8 | public class Program 9 | { 10 | public static void Main(string[] args) 11 | { 12 | var config = new ConfigurationBuilder().Build(); 13 | 14 | var host = new WebHostBuilder() 15 | .UseKestrel() 16 | .UseContentRoot(Directory.GetCurrentDirectory()) 17 | .UseConfiguration(config) 18 | .UseIISIntegration() 19 | .UseStartup() 20 | .Build(); 21 | 22 | host.Run(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:64545/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "LanguageSwitcherTagHelper": { 19 | "commandName": "Project" 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LanguageSwitcherTagHelper 2 | 3 | [http://hishambinateya.com/build-customizable-language-switcher-tag-helper-with-bootstrap](http://hishambinateya.com/build-customizable-language-switcher-tag-helper-with-bootstrap) -------------------------------------------------------------------------------- /Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace LanguageSwitcherTagHelper { 12 | using System; 13 | using System.Reflection; 14 | 15 | 16 | /// 17 | /// A strongly-typed resource class, for looking up localized strings, etc. 18 | /// 19 | // This class was auto-generated by the StronglyTypedResourceBuilder 20 | // class via a tool like ResGen or Visual Studio. 21 | // To add or remove a member, edit your .ResX file then rerun ResGen 22 | // with the /str option, or rebuild your VS project. 23 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 24 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 25 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 26 | internal class Resources { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() { 34 | } 35 | 36 | /// 37 | /// Returns the cached ResourceManager instance used by this class. 38 | /// 39 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 40 | internal static global::System.Resources.ResourceManager ResourceManager { 41 | get { 42 | if (object.ReferenceEquals(resourceMan, null)) { 43 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LanguageSwitcherTagHelper.Resources", typeof(Resources).GetTypeInfo().Assembly); 44 | resourceMan = temp; 45 | } 46 | return resourceMan; 47 | } 48 | } 49 | 50 | /// 51 | /// Overrides the current thread's CurrentUICulture property for all 52 | /// resource lookups using this strongly typed resource class. 53 | /// 54 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 55 | internal static global::System.Globalization.CultureInfo Culture { 56 | get { 57 | return resourceCulture; 58 | } 59 | set { 60 | resourceCulture = value; 61 | } 62 | } 63 | 64 | /// 65 | /// Looks up a localized string similar to <script type="text/javascript"> 66 | /// function appendLanguageSwitcherCookie(code) {{ 67 | /// document.cookie = '{0}=c='+code+'|uic='+code; 68 | /// window.location.reload(); 69 | /// }} 70 | ///</script>. 71 | /// 72 | internal static string LanguageSwitcherScript { 73 | get { 74 | return ResourceManager.GetString("LanguageSwitcherScript", resourceCulture); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | <script type="text/javascript"> 122 | function appendLanguageSwitcherCookie(code) {{ 123 | document.cookie = '{0}=c='+code+'|uic='+code; 124 | window.location.reload(); 125 | }} 126 | </script> 127 | 128 | -------------------------------------------------------------------------------- /Startup.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.Logging; 6 | using Microsoft.Extensions.Options; 7 | using Microsoft.AspNetCore.Razor.TagHelpers; 8 | using LanguageSwitcherTagHelper.TagHelpers; 9 | 10 | namespace LanguageSwitcherTagHelper 11 | { 12 | public class Startup 13 | { 14 | public void ConfigureServices(IServiceCollection services) 15 | { 16 | services.AddLocalization(); 17 | services.AddMvc(); 18 | services.Configure(options => 19 | { 20 | var supportedCultures = new [] 21 | { 22 | new CultureInfo("ar-SA"), 23 | new CultureInfo("ar-YE"), 24 | new CultureInfo("en-US"), 25 | new CultureInfo("fr"), 26 | new CultureInfo("es") 27 | }; 28 | 29 | options.SupportedCultures = supportedCultures; 30 | options.SupportedUICultures = supportedCultures; 31 | }); 32 | 33 | services.AddSingleton(); 34 | } 35 | 36 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 37 | { 38 | loggerFactory.AddConsole(LogLevel.Debug); 39 | 40 | var locOptions = app.ApplicationServices.GetService>(); 41 | app.UseRequestLocalization(locOptions.Value); 42 | 43 | app.UseStaticFiles(); 44 | 45 | if (env.IsDevelopment()) 46 | { 47 | app.UseDeveloperExceptionPage(); 48 | } 49 | 50 | app.UseMvc(); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /TagHelpers/DisplayMode.cs: -------------------------------------------------------------------------------- 1 | namespace LanguageSwitcherTagHelper.TagHelpers 2 | { 3 | public enum DisplayMode 4 | { 5 | Image = 0, 6 | ImageAndText = 1, 7 | Text = 2 8 | } 9 | } -------------------------------------------------------------------------------- /TagHelpers/LanguageSwitcherTagHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Localization; 3 | using Microsoft.AspNetCore.Mvc.Rendering; 4 | using Microsoft.AspNetCore.Mvc.ViewFeatures; 5 | using Microsoft.AspNetCore.Razor.TagHelpers; 6 | using Microsoft.Extensions.Options; 7 | using System; 8 | 9 | namespace LanguageSwitcherTagHelper.TagHelpers 10 | { 11 | [HtmlTargetElement("language-switcher")] 12 | public class LanguageSwitcherTagHelper : TagHelper 13 | { 14 | private readonly IOptions _localizationOptions; 15 | 16 | public LanguageSwitcherTagHelper(IOptions options) 17 | { 18 | _localizationOptions = options; 19 | } 20 | 21 | [ViewContext, HtmlAttributeNotBound] 22 | public ViewContext ViewContext { get; set; } 23 | 24 | public DisplayMode Mode { get; set; } = DisplayMode.ImageAndText; 25 | 26 | public override void Process(TagHelperContext context, TagHelperOutput output) 27 | { 28 | var selectedCulture = ViewContext.HttpContext.Features.Get().RequestCulture.Culture; 29 | var cultures = _localizationOptions.Value.SupportedUICultures; 30 | 31 | output.TagName = null; 32 | 33 | switch (Mode) 34 | { 35 | case DisplayMode.ImageAndText: 36 | output.Content.AppendHtml($@"