Hard and soft G

In the Latin-based orthographies of many European languages, the letter is used in different contexts to represent two distinct phonemes that in English are called hard and soft . The sound of a hard (which often precedes the non-front vowels or a consonant) is usually the voiced velar plosive (as in "gangrene" or "golf)" while the sound of a soft (typically before , , or ) may be a fricative or affricate, depending on the language. In English, the sound of soft is the affricate , as in general", giant", and "gym." A at the end of a word usually renders a hard (as in "rag"), while if a soft rendition is intended it would be followed by a silent (as in "rage").
History.
This alternation has its origins in a historical palatalization of which took place in Late Latin, and led to a change in the pronunciation of the sound before the front vowels and . Later, other languages not descended from Latin, such as English, inherited this feature as an orthographic convention. The Scandinavian languages, however, have undergone their shift independently.
English.
In English orthography, the pronunciation of hard is and that of soft is ; the French soft , , survives in a number of French loanwords (e.g. "regime", "genre"), [ʒ] also sometimes occurs as an allophone of [dʒ] in some accents in certain words.
In words of Greco-Latinate origin, the soft pronunciation occurs before while the hard pronunciation occurs elsewhere. In some words of Germanic origin (e.g. "get", "give"), loan words from other languages (e.g. "geisha", "pierogi"), and irregular Greco-Latinate words (e.g. "gynecology"), the hard pronunciation may occur before as well. The orthography of soft is fairly consistent: a soft is almost always followed by . The notable exceptions are "gaol" (now more commonly spelled "jail") and "margarine" (a French borrowing whose original hard softened for unknown reasons, even though the name "Margaret" has a hard ). The soft pronunciation of "algae", the only one heard in North America, is sometimes cited as an exception, but it is actually conformant, being an alternate spelling for a vowel in the family. Though this pronunciation is listed first in some British dictionaries, hard pronunciation due to misinterpretation of the digraph is widespread in British English and is listed second or alone in some British dictionaries. In some words, a soft has lost its trailing due to suffixing, but the combination would imply the soft pronunciation anyway (e.g. "fledgling", "judgment", "pledgor").
Digraphs and trigraphs, such as , , and , have their own pronunciation rules.
While , which also has hard and soft pronunciations, exists alongside (which always indicates a hard pronunciation), has no analogous letter or letter combination which consistently indicates a hard sound, even though English uses consistently for the "soft" sound (the rationale for the spelling change of "gaol" to "jail"). This leads to special issues regarding the "neatness" of orthography when suffixes are added to words that end in a hard- sound. This additionally leads to many words spelled with g and pronounced with a hard , including what may be the most common g word "get".
Suffixation.
When suffixes are added to words ending with a hard or soft , the sound is normally maintained. Sometimes the normal rules of spelling changes before suffixes can help signal whether the hard or soft sound is intended. For example, as an accidental byproduct of the rule that doubles consonants in this situation after a short vowel, a double will normally indicate the hard pronunciation (e.g. "bagged" is pronounced , not as ).
There are occasional exceptions where alternations between the hard and soft sound occur before different suffixes. Examples are "analogous" (hard) vs. "analogy" (soft); similarly, "prodigal" with "prodigy". These are generally cases where the entire word, including the suffix, has been imported from Latin, and the general Romance-language pattern of soft before front vowels, but hard otherwise, is preserved.
Sometimes a silent letter is added to help indicate pronunciation. For example, a silent usually indicates the soft pronunciation, as in "change"; this may be maintained before a suffix to indicate this pronunciation (as in "changeable"), despite the rule that usually drops this letter. A silent can also indicate a soft pronunciation, particularly with the suffixes "-gion" and "-gious" (as in "region", "contagious"). A silent can indicate a hard pronunciation in words borrowed from French (as in "analogue", "league", "guide") or words influenced by French spelling conventions ("guess", "guest"); a silent serves a similar purpose in Italian-derived words ("ghetto", "spaghetti").
A silent can occur at the end of a word – or at the end of a component root word that is part of a larger word – after as well as word-internally. In this situation, the usually serves a marking function that helps to indicate that the immediately before it is soft. Examples include "image", "management", and "pigeon". Such a silent also indicates that the vowel before is a historic long vowel, as in "rage", "oblige", and "range". When adding one of the above suffixes, this silent is often dropped and the soft pronunciation remains. While commonly indicates a soft pronunciation, the silent may be dropped before another consonant while retaining the soft pronunciation in a number of words such "judgment" and "abridgment." Also, the word "veg", a clipped form of "vegetate", retains the soft pronunciation despite being spelled without a silent (i.e., pronounced as if spelled "vedge"). Similarly, soft is sometimes replaced by in some names of commercial entities, such as with "Enerjy Software", or "Majic 105.7" in Cleveland, Ohio and some names commonly spelled with are given unusual soft spellings such as "Genna" and "Gennifer".
Letter combinations.
English has many words of Romance origin, especially from French and Italian. The ones from Italian often retain the conventions of Italian orthography whereby represents hard before "e" and "i" and "gi" and "ge" represent soft (often even without any semivowel/vowel sound, thus representing /dʒ/ just as "j" usually does in English orthography). The ones from French and Spanish often retain the conventions of French orthography and Spanish orthography whereby represents hard before "e" and "i" and "gi" and "ge" represent soft (often realized as /ʒ/ in French and as /h/ or /χ/ in Spanish). A consequence of these orthographic tendencies is that "g" before "o" or "a" is "almost never" soft in English—one way in which English orthography, which is generally not especially phonemic or regular, displays strong regularity in at least one aspect. A few exceptions include "turgor" and "digoxin", for which the most common pronunciations use soft despite the lack of "softness signal" "gi" or "ge". But both of those words also have hard pronunciations that are accepted variants, which reflects the spelling pronunciation pressure generated by the strong regularity of the digraph conventions. 
A number of two-letter combinations (digraphs) follow their own pronunciation patterns and, as such, may not follow the hard/soft distinction of . For example, often represents (as in "ring") or as in "finger". The letters , when final, represent , as in "orange"; when not final their pronunciation varies according to the word's etymology (e.g. in "danger", in "anger", in "banger"). In most cases, represents as in "dagger", but it may also represent as in "suggest" and "exaggerate". (The same pair of facts can also be said of how relates to hard and soft C, as, for example, in "succinct" and "flaccid".) Other letter combinations that don't follow the paradigm include , , and .
The digraph is sometimes used to indicate a hard pronunciation before (e.g. "guess", "guitar", "Guinness"), including cases where is silent (e.g., "rogue", "intrigue", "catalogue", "analogue"). In some cases, the intervening is pronounced as /w/ ("distinguish", "unguent").
Other languages.
Latin script.
All modern Romance languages make the hard/soft distinction with , except a few that have undergone spelling reforms such as Ladino (Judaeo-Spanish) or Haitian Creole and archaic variants like Sardinian. The hard is in almost all those languages (with the exception of Galician, which may instead be a voiceless pharyngeal fricative), though the soft pronunciation, which occurs before , differs amongst them as follows:
Different languages use different strategies to indicate a hard pronunciation before front vowels:
A soft pronunciation before non-front vowels is usually indicated by a silent or (e.g. Italian "giorno", French "mangeons"), though Spanish, Portuguese, French and Catalan use as in "jueves".
Several North Germanic languages also make a hard/soft distinction. Again, the hard is in most of these languages, but the soft differs as follows:
Icelandic orthography is a bit more complicated by having lenited pronunciations of . 
In German, the g is mostly a hard g, also before "e" and "i": "geben" (to give), "Geld" (money), "Gier" (greed), "Gift" (poison, venom). Soft g occurs in loanwords, usually preserving the original pronunciation. So in words of French origin like "Orange" (orange), "logieren" (to lodge) or "Etage" (floor), the "g" is pronounced as ; words taken from English like "Gin" or "Gender" use the -sound. However others, such as "agieren" (act, agitate), "Generation" (generation) or "Gymnasium" (academic high school), are pronounced with a hard g. Some pronunciations vary by region: The word "Giraffe" is pronounced with a soft G in Austria, but with a hard G in Germany. The "g" in "Magnet" is pronounced as a hard g, but the "gn" in "Champagner" is pronounced like the French "gn" in "champagne". The letter combination "ng" is usually merged to a velar nasal, and the g is not spoken in its own right; e.g., in the German word "Finger", it is not audible as in the English word "finger". However, when those letters are pronounced separately, as in compound words like "Eingabe" (input) or also in verbs like "fingieren" (to feign), both the "n" and the hard "g" is clearly audible. There are exceptions in loanwords like French-derived "rangieren" (to rank, to shunt), spoken with a velar nasal and a soft "g" ().
Other languages typically have hard pronunciations except possibly in loanwords where it may represent or .
The orthography of Luganda is similar to Italian in having a soft pronunciation before front vowels (namely ) and indicates this soft pronunciation.
Because Esperanto orthography is phonemic, always represents a hard g; a soft g is represented by the accented letter 
The Vietnamese alphabet does not have a hard or a soft per se. However, since it was inherited from European Romance languages (Portuguese and Italian) except the diacritics which were from Greek; the letter never occurs in "soft positions", i.e. before , and where the digraph (colloquially known as "gờ ghép" "composed ") is used instead. Likewise, the trigraph ("ngờ ghép" "composed ") also replaces the digraph in those positions. "gh" can be explained as following Italian convention, and "ngh" as a form of analogy. However, there still is which is considered a digraph on its own, even in the word "gì".
Other scripts.
In Modern Greek, which uses the Greek alphabet, the Greek letter "gamma" (uppercase: ; lowercase: ) – which is ancestral to the Roman letters and – has "soft-type" and "hard-type" pronunciations, though Greek speakers do not use such a terminology. The "soft" pronunciation (that is, the voiced palatal fricative ) occurs before and (both which represent ), and before , , , , and (which all represent ). In other instances, the "hard" pronunciation (that is, the voiced velar fricative ) occurs.
In the Russian alphabet (a variant of Cyrillic), represents both hard (твёрдый ) and soft (мягкий ) pronunciations, and , respectively. The soft pronunciation of occurs before any of the "softening" vowels and the hard pronunciation occurs elsewhere. However, the letter functions as a "soft g" in the Romance sense, with alterations between and common in the language (e.g. ложить, "to lie (down)", past tense лёг; подруга, "girlfriend", diminutive подружка). In other Slavic languages, there are similar phenomena involving (or ) and (or ).
In Modern Hebrew, which uses the Hebrew alphabet, the letter "gimel" () typically has the sound within Hebrew words, although in some Sephardic dialects, it represents or when written with a dagesh (i.e., a dot placed inside the letter: ), and when without a dagesh. An apostrophe-like symbol called a Geresh can be added immediately to the left of a gimel (i.e., ) to indicate that the gimel represents an affricate ).