amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Amp-ad placeholder in browser language (feature request)

Open mhmgdk opened this issue 9 years ago • 6 comments

Would it not be nice if the amp-ad placeholder text would follow the browser language?

I have placed a proof of concept below of how this could be applied with help of javascript and a SVG image with an onload call (could be the placeholder).

(copy paste all code below into one html file for viewing in a browser)

<!DOCTYPE HTML> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
</head>
</body>
<script type="text/javascript">
function setLocalizedAdText(evt) {
	var lang, msg;
	lang = navigator.language || navigator.browserLanguage;
	switch (lang) {
		case "da":
			msg = "Annonce";
			break;
		case "no":
			msg = "Annonse";
			break;
		case "se":
			msg = "Annons";
			break;
		case "is":
			msg = "Auglýsing";
			break;
		case "de":
			msg = "Anzeige";
			break;
		case "nl":
			msg = "Advertentie";
			break;
		case "es":
			msg = "Anuncio";
			break;
		case "cz":
			msg = "Reklama";
			break;
		case "lv":
			msg = "Reklāma";
			break;
		case "tr":
			msg = "Reklâm";
			break;
		default:
			msg = "Ad";
	}
	evt.target.getElementsByTagName("text")[0].innerHTML = msg;
}
</script>
<svg version="1.1"
     baseProfile="full"
     width="320" height="320"
     xmlns="http://www.w3.org/2000/svg"
	 onload='setLocalizedAdText(evt)'>
  <defs>
    <filter x="0" y="0" width="1" height="1" id="solid">
      <feFlood flood-color="dimgray"/>
      <feComposite in="SourceGraphic"/>
    </filter>
  </defs>
  <rect width="100%" height="100%" fill="white" />
  <text filter="url(#solid)" x="50%" y="50%" alignment-baseline="middle" text-anchor="middle" font-family="Verdana" font-size="16" fill="white"></text>
</svg>
</body>
</html>

mhmgdk avatar Apr 11 '17 22:04 mhmgdk

You can do this in CSS

:lang('da') .i-amphtml-ad-default-holder:after {
  content: 'Annonce';
}
:lang('se') .i-amphtml-ad-default-holder:after {
  content: 'Annons';
}
/* and so on */

See https://developer.mozilla.org/en-US/docs/Web/CSS/:lang

jpettitt avatar Apr 11 '17 23:04 jpettitt

Hi John,

Excellent solution.

Is there a kind of API documentation on AMP-AD anywhere?

Med venlig hilsen/Best regards

Martin Hansen /Support/

Media Group Denmark ApS Haslegårdsvej 8-10 DK-8210 Aarhus V Tlf.: +454182 6663(direkte) Tlf.: +457220 6663 (hovednr.) www.mediagroupdenmark.dk http://www.mediagroupdenmark.dk /Øget trafik, øget omsætning og et stærkt sammenhold!/ Følg os på LinkedIn https://www.linkedin.com/company/media-group-denmark-aps?trk=company_name

[email protected]: mailto:[email protected]?Subject=Kontakt%20

Den 12-04-2017 kl. 01:39 skrev John Pettitt:

You can do this in CSS

:lang('da').i-amphtml-ad-default-holder:after { content:'Annonce'; } :lang('se').i-amphtml-ad-default-holder:after { content:'Annons'; } /* and so on */

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ampproject/amphtml/issues/8715#issuecomment-293431031, or mute the thread https://github.com/notifications/unsubscribe-auth/AaC8kFOICQKrjVOVMfLuhSBUNqaZNGx2ks5rvA9DgaJpZM4M6tEz.

mhmgdk avatar Apr 12 '17 07:04 mhmgdk

... Except that applying this style tag in does not have any effect at all.

Med venlig hilsen/Best regards

Martin Hansen

mhmgdk avatar Apr 18 '17 09:04 mhmgdk

Weird, do you have a lang="xx" on the html or body should work if the doc is tagged with a language. If you know the document language and you just want to replace the text then this will do it.

<style amp-custom>
 amp-ad [fallback] > div:after {
  content: 'Text for ad placeholder';
}
</style>

Edit: using the amp-ad [fallback] > div:after selector stops the amp runtime complaining about you using .i-amphtml-* classes.

jpettitt avatar Apr 19 '17 23:04 jpettitt

This issue hasn't been updated in awhile. @jasti Do you have any updates?

ampprojectbot avatar Dec 12 '17 02:12 ampprojectbot

Closing with @jpettitt's workaround. Please reopen if this doesn't solve your issue.

jasti avatar Dec 20 '17 14:12 jasti